Simone
Simone

Reputation: 656

setting a combo box value using javascript not working

hi i have 2 combo boxes 1) profile and 2) centre and i am setting the value of 1 based on that selected in the 1st. on change of 1st, correct value is displaying in the 2nd, but the no value is getting posted for the 2nd combo in the form.

please let me know where im going wrong. Here is what i have done:

    var centre=document.getElementById('centre');
if(profile==1)//super admin
 {
 centre.value="AD";
 centre.disabled=true;       

 }
 else 
 {

  centre.value="";
  centre.disabled=false;
 }

I am using codeigniter here so my view is :

    <td><?php echo form_label('Profile','profile'); ?></td>
    <td><?php echo form_dropdown('profile', $profilecombodata,set_value('profile'),$js); ?></td>
    <td style="color: red;"><?php echo form_error('profile'); ?><?php echo isset($errors['profile'])?$errors['profile']:''; ?></td>
</tr>
<?php $js ='id="centre"  onChange="change_profile(this.value);" ';

?>
<tr >
    <td><?php echo form_label('Centre','centre'); ?></td>
    <td><?php echo form_dropdown('centre', $centrecombodata,set_value('centre'),$js); ?></td>
    <td style="color: red;"><?php echo form_error('centre'); ?><?php echo isset($errors['centre'])?$errors['centre']:''; ?></td>
</tr> 

Upvotes: 0

Views: 276

Answers (1)

Kailash Yadav
Kailash Yadav

Reputation: 1930

Disabled fields doesn't get posted with HTTP. You need to make them readonly or Hidden.

Else you need to use javascript or Jquery to send Ajax request.

Upvotes: 1

Related Questions