2011-05-06 59 views
0

我使用這個郵政編碼驗證腳本我在網上找到的,而是僅僅提交表單,並追加到URL的末尾驗證執行js函數,我想它要執行的功能shipCalc()當zip是一個有效的格式。我會在哪裏改變這個來調用函數?JS壓縮時有效

JS

<script language="javascript"> 
function validateZIP(field) { 
var valid = "-"; 
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> 

功能我需要CALL如果有效

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

回答

2

與更換return true;行:

shipCalc(); 
return false; 
+1

你是救世主!非常感謝你的幫助! – livinzlife 2011-05-06 21:39:57