javascript - Struts-JQuery Disable drop down option based on a selection of a different drop down -


in jsp have form multiple drop down items. form using struts-tags declaration.

on form, want disable 1 or more options of 1 drop down based on selection of separate drop down on same form.

here's simple example demonstrate. how have drop downs coded.

<s:select id="vehicletype" name="vehicletype" list="#{'0': 'truck','1':'sedan'}"  <s:select id="vehiclelist" name="vehiclelist" list="#{'0':'ford f150','1':'dodge ram','2':'honda accord','3':'nissan altima'}" 

if select "truck" "vehicletype" drop down, want disable both "honda accord" , "nissan altima" "vehiclelist" drop down. if select "sedan" "vehicletype" drop down, want disable both "ford f150" , "nissan altima" "vehiclelist" drop down.

try following:

function resetvehiclelist(vehicletype) {     $('#vehiclelist option').show();     if($(vehicletype).val() == '0')     {         $('#vehiclelist option[value="2"]').hide();         $('#vehiclelist option[value="3"]').hide();     }     else if($(vehicletype).val() == '1')     {         $('#vehiclelist option[value="0"]').hide();         $('#vehiclelist option[value="1"]').hide();     }     $('#vehiclelist').val($('#vehiclelist option:visible').first().attr('value')); }  $('#vehicletype').change(function(){     resetvehiclelist(this); });  $(document).ready(function(){     resetvehiclelist($('#vehicletype')); }); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -