js zip verification execute js function when valid
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 (fi开发者_如何学Celd.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>
Replace the return true;
line with:
shipCalc();
return false;
精彩评论