events - jQuery show / hide elements by select field -
i have select field shows different elements of form based on selected value, have 3 "classes" each show required portions of filed. have selects bound .click() , works fine except if want load page value preselected, won't show required parts of form because select field hasn't been clicked.
i've looked around , don't see event allow me show information based on selected value, i'm not expert maybe i'm misunderstanding of functions.
here's relevant portion of html:
<select name="class"> <option value="vehicle" selected="selected">vehicle</option> <option value="part">part</option> <option value="project">project</option> <option value="vehicle">vehicle</option> </select><br /> <etc...>
and current jquery switcher:
$("select option[value='project']").click(function() { $('div.part-show').show().hide(); $('div.both-show').hide().show(); $('div.vehicle-show').hide().show(); });
thanks much!
i had similar problem , did work fired off click event (or select event in case) on object wanted preselected.
so...within jquery code following after have setup change function:
$('select option:first').click();
that should fire off event , hide/show immediately.
another option works start off html shown , hidden based on default selected value (just code html). works if going have static default selected value (aka, not dynamic based on other user input).
Comments
Post a Comment