我有默认值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