I have a PHP foreach loop inside a form where the value comes from database. Here, the input ID increases with the element of the loop.
<form class="form-horizontal">
<?php
$count = 0;
foreach ($value as $row) {
$count += 1;
echo
'<div class="row">
<div class="form-group">
<label id="durationLabel' . $count . '">Duration (days)</label>
<input type="number" name="duration_days" value="' . $row['duration_days'] . ' day" class="form-control input-sm" id="durationInput' . $count . '" placeholder="Days" onchange="durationInputChange(this.value,'.$count.')">
</div>
</div>';
}
?>
</form>
Now, my question is, how can I detect if any input value is changed (based on ID) and also get that value and show that in that corresponding Label using jQuery. The current JavaScript code I have doesn't do anything on value change:
function durationInputChange(a,i) {
var d = document.getElementById("durationInput"+i).value;
alert(d);
}