Wednesday, 15 September 2010

php - Dynamically referencing object ID with javascript in Yii -



php - Dynamically referencing object ID with javascript in Yii -

i'm creating tabular input yii, works fine , can save values fields. want add together field next input field, shows value of input field multiplied/divided value. want value updated whenever value in input field changed. input fields created with:

echo $form->textfield($productorder, "[$index]unitsshipped", array( 'onchange' => 'javascript:$("#pallets0").val(this.value/7)' ));

the field next with:

echo $form->textfield($productorder, "unitsshipped", array( 'id' => "pallets".$index, ));

where of above fitted within loop.

the above works, first field, because im statically referencing same field input fields. dont know how can assign dynamically? id pallet field assigned dynamically , if instance set "onchange" reference "pallet1" work, ofc next pallet field.

i've tried concenate strings in javascript, far without luck.

this should work reference current pallets, assuming both fields in same loop index

echo $form->textfield($productorder, "[$index]unitsshipped", array( 'onchange' => 'javascript:$("#pallets'.$index.'").val(this.value/7)' ));

javascript php yii tabular

No comments:

Post a Comment