jquery - How to disable select based on other selected option? -
i have problem jquery function. want based on 1 selected option disable other select. in case, want disable select2 if option 1 select 1 chosen. use jquery function:
$(document).ready(function(e) { $('.select1').change(function(e) { if ($('.select1').val()==1){ $('.select2').attr('disabled','disabled'); } else{ $('.select2').removeattr('disabled'); } }) });
but works if first select option 2(or other option form select) , reselect option 1(i suppose because use of change function). how disable select2 when default select1 set option 1???
$(document).ready(function(e) { if ($('.select1').val()==1){ $('.select2').attr('disabled','disabled'); } else{ $('.select2').removeattr('disabled'); } })
this wont work :/
it sounds want trigger 'change' event @ startup.
$('.select1').trigger('change');
so,
$(document).ready(function(e) { $('.select1').change(function(e) { if ($('.select1').val()==1){ $('.select2').attr('disabled','disabled'); } else{ $('.select2').removeattr('disabled'); } }); $('.select1').trigger('change'); });
Comments
Post a Comment