1

I have five text fields in my page and when the user types something in first textfield, I need to retrieve the values based on the first textfield. Right now, I have hardcode the value as 121, which is returning the value properly from DB, but how do I make it dynamic ?

<?php echo $form->textField(emp::model()->findByAttributes(array('id' => '121' )),'empno');  ?> 
user2431170
  • 151
  • 2
  • 11

2 Answers2

0

You can ajax call for it while typing in the textbox as follows:

$("textbox").on('keyup',function(){

    // use get or post request here to retrieve the data
    $.post('url',{parameters},function(data){
        //code to set the data in you UI
    }

});
Roopendra
  • 7,674
  • 16
  • 65
  • 92
PHP Geek
  • 3,949
  • 1
  • 16
  • 32
0

Use Yii's builtin autocomplete widget for that. It's based on jQuery UI library.

http://www.yiiframework.com/doc/api/1.1/CJuiAutoComplete

$this->widget('zii.widgets.jui.CJuiAutoComplete',array(
    'name'=>'city',
    'sourceUrl'=> "<your keyword suggestion url here>",
    // additional javascript options for the autocomplete plugin
    'options'=>array(
        'minLength'=>'2',
    ),
));
Gihan
  • 4,163
  • 6
  • 31
  • 49