/ Published in: jQuery
I needed a way to show "US States" element whenever the user selected "United States" as their country. Here's a live demo: http://demo.chrisaiv.com/dropdown
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(document).ready(function() { $("#country").bind("change", onSubmitChangeHandler); function onSubmitChangeHandler( e ){ if( $("#country").val() == "United States" ) $("#state").css( "display", "inline" ); else $("#state").css( "display", "none" ); } $("#leftColumn :submit").bind("click", onSubmitClickHandler); function onSubmitClickHandler( e ){ // console.log( "All of the States: " + $('#leftColumn #state *').fieldValue(false) ); // console.log( $('#leftColumn #country *').fieldValue(false) ); console.log( "State: " + $("#state").val() + " (Idx=" + $.inArray( $("#state").val(), $('#state *').fieldValue(false) ) + ")" ); console.log( "Country: " + $("#country").val() + " (Idx=" + $.inArray( $("#country").val(), $('#country *').fieldValue(false) ) + ")" ); } });