Hi, I am facing a problem of updating the textfield with value after a value of dropdownlist is selected. When I select a value from dropdownlist, the dependent textfield is not shown any value out. Anyone knows how to solve this?
First, your are updating div with id="name" instead of updating input field value and then in ajax url action you outputting option tag instead input field value.
Hi,Absar A Hasan. Thanks for the reply. Ohh, that’s my mistake. Do you have any idea on how to solve it? How to make it to update the textfield? Please guide me…
I have tried to change into another method of getting value for textfield after dropdownlist is selected but it is still not working. Could anyone please help me?? I followed the link HERE
I think #name won’t exist on your form. Look at the displayed source code in the browser. I think the actual id of the this $form->textfield() is ‘modelName_name’. So (#name).val() has nothing to point to.
Hi,jkofsky! You are totally right. The id of #name is not exist. Thanks for correcting me but it is still not working after I have changed the ID. Is there anything I miss out again? THe value of textfield is not shown after I select dropdownlist.
I have changed my code and it works fine to me. However, I wish to save ‘code’ instead of ‘name’ into my database. How to solve this problem?
<script type="text/javascript">
function change()
{
var select = document.getElementById('code');
var input = document.getElementById('name');
input.value = select.value;
}
</script>
<div style="margin-left:70px">
<?php echo $form->labelEx($model,'code'); ?>
<div style="margin-left:110px; margin-top:-30px">
//i wish to save the 'code' instead of 'name'. if i change the 'name' to 'code', then the 'name' will not be displayed on the textfield below
<?php echo $form->dropDownList($model,'code', CHtml::listData(Course::model()->findAll(), 'name', 'code'), array(
'empty'=>'Please Select Course Code',
'id'=>'code',
'onchange'=>'{change();}'
)); ?>
</div></div></br>
<div style="margin-left:70px">
<?php echo $form->labelEx($model,'name'); ?>
<div style="margin-left:110px; margin-top:-30px">
<?php echo $form->textfield($model,'name', array('id'=>'name','disabled'=>true));?>
</div></div></br>
If I change ‘name’,‘code’, then it will save name for the both dropdownlist and textfield into the database.
If I change ‘code’,‘name’, then it will save code for the both dropdownlist and textfield into the database.
How am I going to solve the problem if I want to save code for dropdownlist and name for textfield into the database?? Hope you can understand what I am trying to explain here. Thank you.