[英]disabling submit button till input fields are validated
i have disabled the submit button in my guestbook. 我已禁用留言簿中的“提交”按钮。 it has 2 fields[name(textbox)&comment(textarea)].it has 2 other fields ID(primary key) and date.the function is:
它有2个字段[name(textbox)&comment(textarea)]。它还有2个其他字段ID(主键)和date。该函数是:
function Frmvalidate() {
var nmchk=document.forms["guestform1"]["name"].value;
var cmntchk=document.forms["guestform1"]["comment"].value;
if (nmchk.length==0)
{
var namep = document.getElementById("namep");
namep.innerHTML="name must be filled out";
return false;
}
else if (cmntchk.length==0)
{
var cmntp = document.getElementById("cmntp");
cmntp.innerHTML="comment must be filled out";
return false;
}
else
{
document.getElementById("sbmt").disabled=false;
return true;
}
} }
i have called the function in places: body tag's onload,button tag's onclick. 我已经在某些地方调用了该函数:body标签的onload,button标签的onclick。 still its not working and blank entries are being stored in my database.
仍然无法正常工作,空白条目存储在我的数据库中。
You dont need to disable the submit button 您不需要禁用提交按钮
you gain noting from it. 您会从中注意到。 ( alerting the user , running another script etc...)
(警告用户,运行其他脚本等)
instead -- The submit button should stop its regular behaviour by this code : 相反-提交按钮应通过以下代码停止其常规行为:
<input type="submit" onclick="return Frmvalidate();"/>
meaning : 含义:
when you press the button , it will execute the function yielding True or False and if it's True (only) it will continue to the server. 当您按下按钮时,它将执行产生True或False的函数,并且如果它是True(仅),它将继续到服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.