View Full Version : I need a "Country's State" code

02-20-2003, 09:02 PM
Hi there.
I have a form to compile my user's information, in this form I have a field "Country" and a field "State", what I'm looking for is a script that displays the list of the states in the "State" field depending on what country has being selected.
I know is not that hard to develop, but I dont know every State of many Countries, so what I really want from that script is the list of the states of several countries.

If any one have any idea whre to find it please tellme


Quiet Storm
02-20-2003, 09:53 PM
I've got something like that:

Will show the states if USA is picked, but not other countries.

02-20-2003, 11:27 PM
Thanx, but actually I'm looking for the list of states-contries, most of all...

But thanx any way

Quiet Storm
02-20-2003, 11:55 PM
I picked this example off of the net somewhere. You'd have to fill in all the details, though. :(

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<body bgcolor="#FFFFFF">
<h1 align="center">Select a country and a state. </h1>
<div align="center">
<form name="form1">
<select name="select" size="1" onChange="pop2();">
<option selected>Australia</option>
<p> <b>State</b>
<select name="select2">
<option selected>NSW</option>
<option>South Australia</option>
<option>Western Australia</option>
<SCRIPT language="javascript">
function pop2() {
var currentlength = window.document.form1.select2.length
for (var i=0; i < currentlength; i++) {
window.document.form1.select2.options[0] = null
if (window.document.form1.select.selectedIndex == 0) {
window.document.form1.select2.options[0] = new Option('aussiestate1');
window.document.form1.select2.options[1] = new Option('aussiestate2');
if (window.document.form1.select.selectedIndex == 1) {
window.document.form1.select2.options[0] = new Option('USstate1');
window.document.form1.select2.options[1] = new Option('USstate2');
if (window.document.form1.select.selectedIndex == 2) {
window.document.form1.select2.options[0] = new Option('canadastate1');
window.document.form1.select2.options[1] = new Option('canadastate2');


02-21-2003, 12:01 AM

Quiet Storm
02-21-2003, 12:01 AM
Here's another one - may be easier to configure:

<script language="javascript">
var USA_Array = new Array();
var Sri_Array = new Array();
var China_Array = new Array();
USA_Array[0] = "AL";
USA_Array[1] = "AK";
USA_Array[2] = "AZ";
USA_Array[3] = "AR";

Sri_Array[0] = "CL";
Sri_Array[1] = "GN";
Sri_Array[2] = "MK";

China_Array[0] = "SH";
China_Array[1] = "HK";

function pop(){
var array;
if(document.form.country[document.form.country.selectedIndex].value == 1)
array = USA_Array;
else if(document.form.country[document.form.country.selectedIndex].value == 2)
array = Sri_Array;
array = China_Array;
document.form.state.options[i] = new Option(array[i],array[i]);

<form name="form">
<select name="country" onchange="pop()">
<option value="None">--- select ---
<option value="1">USA
<option value="2">Srilanka
<option value="3">China

<select name="state">
<option value="None">--- select ---


02-21-2003, 12:11 AM
Thnx for the tip joh6nn but I knew that usefull tool already...
but thnx any way I guess I'll have to write it all by myself

Quiet Storm
02-22-2003, 09:12 PM
I got to thinking about this, and think it would be a real neat idea to have cities of different countries (not just the US). I've started a little something with the code I posted above:


Cities for Algeria, Angola, Argentina, Australia, Brazil, Canada, French Polynesia, and the US states are all I have up so far... out of 241 countries.

Good idea, thanks for posting this question - made me think. ;)

02-22-2003, 11:11 PM
could you put a select box with the continents first? europe, americas... so lazy poeple like me dont have such a big list to scroll through when it gets to the countries... ;)

Quiet Storm
02-23-2003, 01:40 AM
I'll look into it.


Quiet Storm
03-17-2003, 09:57 PM
Originally posted by redhead
could you put a select box with the continents first? europe, americas... so lazy poeple like me dont have such a big list to scroll through when it gets to the countries... ;)

Got it:


03-18-2003, 09:49 AM
heh heh heh! that looks fantastic... nice one...

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum