HTML form show fields depending on drop down selected

haddel

New Member
Having an issue here. Trying to make certain fields appear depending on what has been selected in a drop down box. I"ve had a look on stack and have tried editing the code here:http://jsfiddle.net/tarleton/p8ARq/15/to work with mine. I cannot seem to get it to work...total newbie here so any help appreciated.\[code\]$("select").change(function () { // hide all optional elements $('.optional').css('display','none'); $("select option:selected").each(function () { if($(this).name() == "test") { $('.test').css('display','block'); } else if($(this).val() == "test2") { $('.test2').css('display','block'); } });});\[/code\]HTML:\[code\]<form class="contact" name="contact" action="#" method="post"> <div id="styled-select"> <select> <option name="test" value="http://stackoverflow.com/questions/15628824/Option 1" >Referral</option> <option name="test2"value="http://stackoverflow.com/questions/15628824/Option 2">Other</option> </select> </div> <input class="optional test" name="revealtest" style="display:none;" class="hidden-txt"> <input class="optional other" name="revealtest2" value="" style="display:none;" class="hidden-txt"></form>\[/code\]
 
Back
Top