How to pass current textfield "ID" value to javascript function ?
In my form i am having multiple rows with textfields. I am having a scenario to calculate the total cost based on other two text fields. I am thinking of passing the current textfield id value to identify the row from where i need to get value for calculation and update. I am trying in the below way but i could not make it work. If anyone have suggestions , help me on this issue.
I’m not sure I have completely understood you, but by the looks of things you are manually creating text fields (not activeTextFields from a model) that you then want to sum in a javascript function.
If this is the case, first of all, unobtrusive javascript patterns would dictate that you don’t use the onblur attribute, but rather that you attach a blur event handler to the particular element afterwards.
So for this, I would simply suggest that you manually set the id for the textfields (by including "id" => "elementId" in the htmlOptions array for the textfield), and then register a javascript function (Yii::app()->getClientScript()->registerScript) for the appropriate event using the id you assigned to the textfield.
Well I’m still not sure exactly what it is you want to calculate, but as an example, I’ll assume that you are actually using activetextfields from a model for your values and adding one for your total (so $form is a CActiveForm instance):
So you use your model fields as usual, add your total textfield (which I have disabled since presumably it will only be calculating automatically, not actually accepting any user input), then you register two scripts - the first one registers the function for updating the total with the values from our two model fields, and the second one binds an event handler to those two model fields to trigger this update whenever they lose focus.
Thanks a lot for your time. In my form, i am having array of text fields with id value generated automatically(By using cloning i am doing that). For example, like the below.
I can’t use CHtml::activeID method to retrieve the id’s since i am not using model in the textfield. Something i need to retrieve the current row id and pass it to javascript function. Any suggestions ?
Hello can anyone help me. I have a listbox. I want to add the selected items of listbox to the dropdownbox. means the numbers of items in drop down must be same as the selected items in the listbox. Its very urgent please help me.