I need to populate a textfield automatically based on the input of another textfield.
The scenario is,
<?php echo $form->textField($model,'patientId',array('size'=>21.5,'maxlength'=>10)); ?>
<?php echo $form->textField($model,'Nic',array('size'=>21.5,'maxlength'=>10)); ?>
The NIC must get populated (from the database) according to the patientID textfield input, or vice versa
Any ideas of how this could be accomplished
It can be done in several ways, for example:-
- Add a submit button to post back data of patient id to your controller (dont forget to include fields in form)
- controller then finds the NIC based on patient id using model, and render the same page to display both patient id and nic.
given you food for thought
Use Ajax as
url:'<?php echo Yii::app()->createUrl('site/getnic')?>',
Thanks, I have one more query. I tried this out but it does not work. I included the ajax code in the view _form.php file at the top under the <script> tag
have you check the ids of the input fields? It was just an example code with dome ids.