0

I am using this zip code verification script I found online but instead of just submitting the form and appending it to the end of the url, I would like for it to execute function shipCalc() when the zip is a valid format. Where would I alter this to call the function?

JS

<script language="javascript">
function validateZIP(field) {
var valid = "0123456789-";
var hyphencount = 0;

if (field.length!=5 && field.length!=10) {
alert("Please enter your 5 digit or 5 digit+4 zip code.");
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in your zip code.  Please try again.");
return false;
}
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
return false;
}
}
return true;
}
</script>

HTML

<form name="form9" onSubmit="return validateZIP(this.zip.value)">
Zip: <input type="text" size="10" name="zip">
<input type="submit" value="Submit">
</form>

FUNCTION I NEED TO CALL IF VALID

<script language="javascript">
function shipCalc() {
$('#cartdialog').load("/ash/shop/shipping.php?zip=" + document.form9.zip.value);
}
</script>

1 Answer 1

2

Replace the return true; line with:

shipCalc();
return false;
Sign up to request clarification or add additional context in comments.

1 Comment

you are a savior! Thanks so much for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.