Passing a form field value in CHtml::ajax

Well, I have the ajax call firing in my code, but I'm completely stuck. Here's the line:

<?php echo CHtml::activeTextField($form,'zip',array('size'=>'5','onblur'=> CHtml::ajax(array('data'=>'zip=','url'=>$this->createUrl('zipLookup'),'success'=>'function(){}'))));?>


The problem is, this is in the onblur of a zipcode text field. Where it says zip=, I need to put something following the equal sign that will cause the eventual generated javascript to send the value of the text field.  I've tried having :

this.value


'this.value'


'this.value'


+this.value+


all not working. The ajax call ends up sending the string 'this.value' as the data.

hi

try

js:this.value

seems like this is how yii expects a value that should not be quoted

No joy. I have tried zip=js:this.value, zip='+js:this.value+', zip=&#039;js:this.value&#039;, and zip=&#039;+js:this.value+&#039;, among others.

Looking at the ajax trace in firebug, in one case zip= will not be sent at all, in all the other cases, what is sent is what is shown, for example, the ajax params will have:

zip  js:this.value

or

zip  +js:this.value+

I know there must be some way to send the contents of a form field through ajax, but my mind shuts down when I start thinking, “this is a php call, and I’m concerned about sending a value via javascript, and that value doesn’t exist at the time that the php is being evaluated, but the php needs to put something in the javascript it creates so that javascript will then evaluate IT and …”  yikes.

try sending an array as data parameters

Are you saying then that

CHtml::ajax(array('data'=>'zip='

should change to

CHtml::ajax(array('data'=>array('zip=>'

If so, I'm still left with what I pass as the value side of the 'zip' key, so that when the page is eventually rendered, the javascript will take the value of the text field at that time and plug it into the array.

CHtml::ajax(array('data'=>array('zip' => 'js:this.value'));
?

Bingo!  ;D  Thanks.

One more question. If I want the onblur to have a javascript 'if' statement, such as onblur:if(this.value.length==5){ ajax call,  how would I do that?  I tried putting

'onblur'=>'if(this.value.length==5){'.CHtml::ajax…  but that doesn't seem to be it.