Developer
Developer

Reputation: 3998

where to write jquery ajax in yii form

I"m trying to write custom auto complete for text field. can anyone pls tell me where to write this jquery, ajax code for this textfield in yii..

 <div id="output" class="row">
            <?php echo $form->labelEx($model,'id'); ?>
      <?php echo $form->hiddenField($model,'id'); ?>
      <?php echo $form->textField($model,'id');
      '$(function () {
        $("#search").change(function(){

      $.ajax({url:BASE_URL + '/controller/lookup/',
                    type:"POST",
                    data:this.value,
                    success:function(data){
                   $("#output").html(data);
      }
      });

      });
              });'?>

any help pls,

Many Thanks

Upvotes: 0

Views: 1374

Answers (2)

Harish Ambady
Harish Ambady

Reputation: 13121

Try Yii::app()->clientScript->registerScript instead of Yii::app()->getClientScript()->registerScript

Upvotes: 1

Ohgodwhy
Ohgodwhy

Reputation: 50787

You should just make a new file, call it, 'myFuncs.js'. Place in a directory within your Yii Web App.

Then, in your view, simply call the js file.

Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/path/to/your/scripts/myFunc.js');

Upvotes: 1

Related Questions