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" />

Recommended Answers

All 4 Replies

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...

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?

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>

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.