我有默認值0 2個文本框和一個提交button.Before提交我打電話javascript函數onSubmit="return(validate_myfrm());
以下」。我是無法與價值0.But驗證text_1
爲text_2
默認值0被驗證。如何在使用javascript提交前驗證文本框?
function validate_myfrm()
{
var ans;
if(document.myfrm.txt_1.value=="" ||document.myfrm.txt_1.value==0)
{
ans=confirm("Do you still want to continue with value 0 for text 1?");
if(ans== true)
{
document.myfrm.txt_1.value=0;
document.myfrm.txt_2.focus();
}
else
{
document.myfrm.txt_1.focus();
}
return false;
}
if(document.myfrm.txt_2.value=="" ||document.myfrm.txt_2.value==0)
{
ans=confirm("Do you still want to continue with value 0 for text 2?");
if(ans== true)
{
document.myfrm.txt_2.value="0";
return true;
}
else
{
document.myfrm.txt_2.focus();
}
return false;
}
return true;
}
如果我返回true; document.myfrm.txt_2.focus();
後的頁面將被重定向到下個頁面確認值txt_2.Pls幫助
好.. @ Marc我編輯過。 – Atit 2013-04-22 09:31:22