我正在使用我在网上找到的这个邮政编码验证脚本,但不是只提交表单并将其附加到网址的末尾,我希望它在zip是有效格式时执行函数shipCalc()。我会在哪里改变它来调用函数?
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>
功能我需要打电话有效
<script language="javascript">
function shipCalc() {
$('#cartdialog').load("/ash/shop/shipping.php?zip=" + document.form9.zip.value);
}
</script>
答案 0 :(得分:2)
将return true;
行替换为:
shipCalc();
return false;