David Newcomb
David Newcomb

Reputation: 10943

Referencing Yii form variables inside a Javascript function using jQuery

I have a Yii CActiveForm backed with a CFormModel and I'm using the onChange htmlOption to call the javascript send(). The send function tweeks some of the form variables and populates a hidden field ready for form serialising and POSTing back to the server.

My problem is that I don't know how to reference the form fields from inside the javascript function using jQuery because the CActiveForm changes their names. Currently I'm having to hard code the names eg $('#SearchForm_myvar').val("myval"); which doesn't seem right. How can I reference the form variables inside the javascript code?

Upvotes: 0

Views: 96

Answers (1)

David Newcomb
David Newcomb

Reputation: 10943

Found the answer from the source so putting it here in case someone else wants it. The jQuery id is:

"#" . CHtml::activeId($model,'myvar')

Upvotes: 1

Related Questions