Return to Snippet

Revision: 18891
at October 11, 2009 13:16 by chrisaiv


Initial Code
$(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) ) + ")" );
	}
});

Initial URL

                                

Initial Description
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

Initial Title
jQuery: Capturing Drop Down Data + Show / Hiding Secondary Drop Downs

Initial Tags
jquery

Initial Language
jQuery