I'm creating a tabular input with Yii, this works fine and I can save the values for all fields. However I also want to add a field next to the input field, that shows the value of input field multiplied/divided with another value. I want this value to be updated whenever the value in the input field is changed. My input fields are created with:
echo $form->textField($productorder, "[$index]unitsShipped", array(
'onchange' => 'javascript:$("#pallets0").val(this.value/7)'
));
The field next to it with:
echo $form->textField($productorder, "unitsShipped", array(
'id' => "pallets".$index,
));
Where all of the above is fitted inside a for loop.
The above works, but only for the first field, because im statically referencing the same field for all my input fields. But I dont know how I can assign this dynamically? The ID for my pallet field is assigned dynamically and if I for instance set the "onchange" reference to "pallet1" this will work, but ofc only for the next pallet field.
I've tried to concenate the strings in the javascript, but so far without luck.
This should work you to reference the current pallets, assuming both the fields are in the same loop with index
echo $form->textField($productorder, "[$index]unitsShipped", array(
'onchange' => 'javascript:$("#pallets'.$index.'").val(this.value/7)'
));