Avatar of Ian White
Ian White
Flag for Australia asked on

Invoke cfquery for state/province retrieval when country selected on same page

I have a coldfusion generated selection list that defaults a country selection according to visitor location.

Further down the page is a state/ province list with a select query with the country input from the country selected in the list above.

I want to pass the country to the  query depending on reselection of country so the appropriate states/provinces selection is selected further down the page without the user havin to leave the page.

Eg May arrive on page with Canada preselected but visitor may want to select USA , Australia etc.  

The dynamic/ select  input field is free format entry for countries without states,

Solution using ColdFusion6/  java script
Tip of page

<cfinclude template = "include_country_select_housaesit.cfm">

  <CFSWITCH EXPRESSION="#PassedCountry#">
  

	
 	<CFCASE Value="Australia,United States,Canada">
	
	    <cfif isDefined ("url.sta")
		and url.sta GT " ">
		
		<cfoutput>
		<CFSELECT Name="Crit1_Value" 
		Message="Please select State " 
		QUERY="GetStates"
		Size=1 
		Value="State"
		Selected = "#url.sta#"
		Display="State"
		Required="Yes">
		</CFSELECT>
		</cfoutput>
 	   
	   <cfelse>
	   
	    <CFSELECT Name="Crit1_Value" 
		Message="Please select State " 
		QUERY="GetStates"
		Size=1 
		Value="State"
		Display="State"
		Required="Yes">
		</CFSELECT>
		
		</cfif>
		
	</CFCASE>
	<CFDEFAULTCASE>
		<CFINPUT Type="Text" Name="Crit1_Value" 

		Maxlength="30"
		Size="20"  >
	</CFDEFAULTCASE>
	
</CFSWITCH>

Open in new window

Web ServersJavaScript

Avatar of undefined
Last Comment
Ian White

8/22/2022 - Mon
Proculopsis


You can use something dynamic, as below but loading it asynchronously via ajax might be better for you:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<title>http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/Q_27049864.html</title>
<script type="text/javascript" src="http://filedb.experts-exchange.com/incoming/2011/05_w20/458595/jquery-1.5.2.min.js"></script>
<script type="text/javascript">

var world = {
  "Australia": [ "New South Wales", "Victoria", "Queensland", "Western Australia", "South Australia", "Australian Capital Territory", "Tasmania", "Northern Territory" ],
  "United States": [ "Alaska", "South Dakota", "Wyoming", "Montana", "North Dakota", "Vermont" ],
  "Canada": [ "Ontario", "Quebec", "Nova Scotia", "New Brunswick", "Manitoba", "British Columbia", "Prince Edward Island", "Saskatchewan", "Alberta", "Newfoundland and Labrador" ]
};

jQuery(document).ready( function() {

  for ( var country in world ) {
    $("#country").append( $("<option/>").text( country ) );
  };
  $("#country").change( countryChange );
  countryChange.apply( $("#country") );

});

function countryChange() {
  var country = $(this).val();
  $("#state").empty();
  for ( var state in world[country] ) {
    $("#state").append( $("<option/>").text( world[country][state] ) );
  }
}

</script>

</head> 
<body> 

<select id="country"></select>
<select id="state"></select>

</body>
</html>

Open in new window

SOLUTION
Ian White

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Ian White

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Ian White

ASKER
This is an elegent solution using cold fusion
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23