php - Enable dropdown box based on other dropdown selection -
i have 2 dropdown boxes, 1 role , 1 partner type, if role equal partner want enable dropdown partner type. using codeigniter , jquery. here code not working properly, when change 1st dropdown, 2nd dropdown keep disabled. maybe wrong in code.
<div class="form-group"> <label>role</label> <?php $role_id = array( 'value' => set_value('role_id'), ); $role_options = array( '9' => 'super-admin', '10' => 'admin', '11' => 'partner', '12' => 'reporting', ); $role_ids_name = array( 'name' => 'role_id', 'id' => 'role_id', 'class' => 'form-control', ); echo form_dropdown('role_id', $role_options, set_value('role_id', $role_id), array('id' => 'role_id', 'class' => 'form-control','onchange'=>'enabletype($(this));')); ?> </div> <script type="text/javascript"> function enabletype(obj) { var selectedtext = obj.children(':selected').text(); if(selectedtext == 'partner'); { //enable partner type $('type_id').attr('disabled',false); } else { //disable partner type $('type_id').attr('disabled',true); } } </script> <div class="form-group"> <label>partner type</label> <?php $type_id = array( 'value' => set_value('type_id'), ); $type_options = array( '3' => 'photographer', '4' => 'house sitter', '6' => 'banker', '7' => 'lawyer', '8' => 'insurance agent', ); $type_id_name = array( 'name' => 'type_id', 'id' => 'type_id', 'class' => 'form-control', 'disabled' => 'disabled', ); echo form_dropdown('type_id', $type_options, set_value('type_id', $type_id), $type_id_name); ?> </div>
i solve problem , here code:
<script> $("#role_id").on("change", function(){ var selected = $(this).val(); if(selected == 11) { $('#type_id').attr('disabled',false); } else { $('#type_id').attr('disabled',true); } }) </script>
Comments
Post a Comment