In Yii framework using html elements for displaying contents. In that want to pass the ($i
) values on the onchange
method and calculation done in script. Only the first value is coming always on onchange
method. Want to get current value of ($i
) which is looping in foreach
loop.
<?php $i=0; foreach($sub_marks as $sub) { $i++?>
<td>
<?= Html::textInput('reg_cia'.$i,"",['id'=>'reg_cia','style'=>'width:40px']); ?>
</td>
<td>
// Here the onchange method only first value is passing always
<?= Html::textInput('reg_ese'.$i,$i,['id'=>'reg_ese','tabindex'=>'1','style'=>'width:40px','onchange'=>'js:alerts()'])?>\
</td>
<td>
<?= Html::textInput('reg_total'.$i,"",['id'=>'reg_total','style'=>'width:40px']); ?>
</td>
</tr>
<?php } ?>
<?php } ?>
</table>
<script>
function alerts()
{
var a="reg_cia";
var b="reg_ese";
var s=document.getElementById(a).value;
var g=document.getElementById(b).value;
alert(s+g);
}
</script>