retrieve data from database in textfield on keypress

hello there,

how can i get a value from mysql database from a textfield and display it from another textfield.

Thanks in advance.

Can U please explain this a bit, what exactly U want to do

if iam i the _form how can i get a value from database on a keypress event of textfield in the _form.


 // in your controller set a action that responds with the data you would like to 

    // add in your field

    public function actionValue()

    {

        $user = User::model()->findByPk(1);

        echo $user->name;

    }

    

    // input field

    <?php echo CHtml::textField('username', '', ['id' => 'username']); ?>


    // make sure jquery is loaded 

    <script type="text/javascript">

        $(function() {

            $('#username').on('keyup', function() {

                $('#username').load('<?php echo $this->createUrl("site/value") ?>');

            });

        });

    </script>

Thanks for the help. It works fine…