0

I have been trying to get javascript to work for this but no luck. What I am needing is: I have a drop down box for a person to select COUNTRY either US or Canadian. If it is US then I need a zip code box to display and validate zip for US. If they select Canada I need the same box to validate for Canadian zip code. Any ideas or help with this would be very much appreciated. Can this be done in .asp? If not I can send the javascript code that I can't get to work if that would help.

<select name="COUNTRY" id="COUNTRY">
                <option value="United States">United States</option>
                <option value="Canada">Canada</option>
              </select>

<input name="ZIP" type="text" id="ZIP" size="7" maxlength="10" />
2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by ammwebmaster2
0

instead of textbox make the zip field a combobox and it's values will depend on what country you select.. you can do this thru javascipt..in this case you don't need to validate zip info...

0

So what you are saying is build a selection list that contains all the US zip codes and then one with all Canadian zip codes?

0

no.. just one selection list for all zip codes,, here try this code..

<html>


<head><title>Fill Zipcode</title></head>


<body>
<script type="text/javascript">
function fillzipcode(country)


{
//clear first before populating combobox
document.getElementById("zipcode").options.length = 0;


var combo = document.getElementById("zipcode");


if (country == "Canada")
{
//canada zipcodes here
var option = document.createElement("option");
option.text = "123"; option.value = "123";combo.add(option)



var option = document.createElement("option");
option.text = "321"; option.value = "321"; combo.add(option)



}
if (country == "USA")
{
//usa zipcodes here
var option = document.createElement("option");
option.text = "abc"; option.value = "abc";combo.add(option)



var option = document.createElement("option");
option.text = "cba"; option.value = "cba"; combo.add(option)


}
}
</script>
<form name="frm" id="frm">



Country :
<select name="country" id="country" onChange="fillzipcode(document.frm.country.value);">
<option value="">Choose One</option>
<option value="Canada">Canada</option>
<option value="USA">USA</option>
</select>
<br><br>
Zipcode :
<select name="zipcode" id="zipcode">
</select>



</form>
</body>
</html>

Edited by Nick Evan: Fixed formatting

0

Thank you so much I will see what I can do with this code. I will have to create a selection list with all the zip codes which will take quite some time to do and find a list for Canadian zips to put with the US.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.