Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Swapping Drop Down menus
Old 07-14-2006, 02:13 PM Swapping Drop Down menus
D-Bot's Avatar
Novice Talker

Posts: 5
Name: Darren Johnston
Location: Winnipeg, Canada
Trades: 0
If you have a couple drop down menus with the first one say titled "Country" how would you get the second drop down menu to display the appropriate choices after the first drop down choice has been made? For example: If I have a drop down menu that asks me to select what Country I'm from and I choose "USA" then how do I get the second drop down menu to display all the States to choose from? And if I choose "Canada" for the frist drop down then the second dro down would display all the Provinces to choose - and no States. I hope this makes sense. Does anyone have any wisdom to share? I'm just getting a bit deeper into programming and any help would be appreciated.

TIA
__________________
- It's not what you don't know that will hurt you; it's what you don't know you don't know.
D-Bot is offline
Reply With Quote
View Public Profile Visit D-Bot's homepage!
 
 
Register now for full access!
Old 07-14-2006, 02:31 PM Re: Swapping Drop Down menus
LadynRed's Avatar
Defies a Status

Posts: 10,016
Location: Tennessee
Trades: 0
Do you want a MENU or are you doing a form ??
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Old 07-14-2006, 02:55 PM Re: Swapping Drop Down menus
D-Bot's Avatar
Novice Talker

Posts: 5
Name: Darren Johnston
Location: Winnipeg, Canada
Trades: 0
It's for a form. Sorry, I guess I should have mentioned that.
__________________
- It's not what you don't know that will hurt you; it's what you don't know you don't know.
D-Bot is offline
Reply With Quote
View Public Profile Visit D-Bot's homepage!
 
Old 07-14-2006, 03:10 PM Re: Swapping Drop Down menus
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
You would have to use javascript for that, here is an example:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
		<script type="text/javascript"><!--
var usa = new Array("Alabama","Alaska","American Samoa","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","District Of Columbia","Federated States Of Micronesia","Florida","Georgia","Guam","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Marshall Islands","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Northern Mariana Islands","Ohio","Oklahoma","Oregon","Palau","Pennsylvania","Puerto Rico","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virgin Islands","Virginia","Washington","West Virginia","Wisconsin","Wyoming");
var countries = new Array(usa);


function getNext() {
	countryListBox = document.FormName.countries;
	if (countryListBox.value != "") {
		statesListBox = document.FormName.states;
		//clear states box
		for (i in statesListBox.length) {
			statesListBox.options[i] = null;
		}
		statesListBox.disabled = false;
		stateList = countries[countryListBox.value];
			statesListBox.options[0] = new Option("Choose a State...","");
		for (s in stateList) {
			statesListBox.options[parseInt(s)+1] = new Option(stateList[s],stateList[s]);
		}
	}
}
//-->
</script>
	</head>

	<body bgcolor="#ffffff">
		<form id="FormName" action="yourscript.php" method="get" name="FormName">
			<select name="countries" size="1" onchange="getNext(this)">
				<option value="">Choose A State</option>
				<option value="0">United States</option>
			</select>
			<select name="states" size="1" disabled onchange="alert(this.value);">
				<option value="">Choose A State</option>
				<option value="0">United States</option>
			</select>
		</form>
		<p></p>
	</body>

</html>
Create an array for each country's states, naming the the array the name of the country:
Code:
var usa = new Array("Alabama","Alaska","American Samoa","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","District Of Columbia");
var uk = new Array("Manchester","London","South Newington");
(I don't know UK provinces offhand )
Then in the countries array, put each country array in the order of the drop down:
Code:
var countries = new Array(usa,uk,canada);
and number your select values the same ordinal as they are in the countries array.
There might be a better way to do it, this is the one that came quickest off the top of my head.

Last edited by funkdaddu; 07-14-2006 at 03:16 PM..
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 07-15-2006, 01:36 AM Re: Swapping Drop Down menus
Silent77's Avatar
Ultra Talker

Posts: 269
Name: Silent
Location: Ohio
Trades: 0
Dynamic Drive also has a script like this.

http://www.dynamicdrive.com/dynamici...ects/index.htm
__________________
Firefox
rediscover the web

Please login or register to view this content. Registration is FREE
Down with internet explorer!
Silent77 is offline
Reply With Quote
View Public Profile Visit Silent77's homepage!
 
Old 07-15-2006, 06:26 AM Re: Swapping Drop Down menus
D-Bot's Avatar
Novice Talker

Posts: 5
Name: Darren Johnston
Location: Winnipeg, Canada
Trades: 0
Thanks a lot guys. I really appreciate the help. I'll let you know how I make out.
__________________
- It's not what you don't know that will hurt you; it's what you don't know you don't know.
D-Bot is offline
Reply With Quote
View Public Profile Visit D-Bot's homepage!
 
Reply     « Reply to Swapping Drop Down menus
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.46433 seconds with 12 queries