admin管理员组文章数量:1429728
I am trying to run a form validation on an HTML form to make sure the person has filled out the two fields. I put together a JSFiddle here:
/
It has worked previously for me and I don't know what's going on now. I made a JSFiddle to pull it out of my site to make sure nothing else was conflicting with it but I'm realizing now that it's something in the code. The two fields are name "emailaddress" and "Name" respectively and it looks like I'm checking their values correctly. Basically, I'm looking for an alert (and NOT a submittal of the form) if they've left either field blank. Thanks for helping me track down the problem. I appreciate it.
function ValidateForm(){
var emailID=document.MailingList.emailaddress
var nameID=document.MailingList.Name
if ((nameID.value==null)||(nameID.value=="")){
alert("Please Enter your Name");
nameID.focus();
return false;
}
if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID");
emailID.focus();
return false;
}
}
Even though there is not return true, the form still submits.
I am trying to run a form validation on an HTML form to make sure the person has filled out the two fields. I put together a JSFiddle here:
http://jsfiddle/yCqqj/
It has worked previously for me and I don't know what's going on now. I made a JSFiddle to pull it out of my site to make sure nothing else was conflicting with it but I'm realizing now that it's something in the code. The two fields are name "emailaddress" and "Name" respectively and it looks like I'm checking their values correctly. Basically, I'm looking for an alert (and NOT a submittal of the form) if they've left either field blank. Thanks for helping me track down the problem. I appreciate it.
function ValidateForm(){
var emailID=document.MailingList.emailaddress
var nameID=document.MailingList.Name
if ((nameID.value==null)||(nameID.value=="")){
alert("Please Enter your Name");
nameID.focus();
return false;
}
if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID");
emailID.focus();
return false;
}
}
Even though there is not return true, the form still submits.
Share Improve this question edited Dec 2, 2012 at 17:47 MillerMedia asked Dec 2, 2012 at 17:15 MillerMediaMillerMedia 3,66118 gold badges75 silver badges154 bronze badges3 Answers
Reset to default 4the problem is that you haven't defined ValidateForm in the Head
section.
i have edited the jsfiddle.check demo.
I can see two problem:
First, what is echeck? If I take that code away it will work. Second you should not do return after your control of the nameID.value. If you do that your control of the emailID.value will not be done.
To piggyback on Behnam's answer, it is because ValidateForm isn't defined in the head section as he said. But here's how to fix it:
In jsfiddle, in the upper left area in Frameworks & Extensions, set it to no-wrap . Then update and set as base to save your changes.
本文标签: javascriptForm validation not running onsubmitStack Overflow
版权声明:本文标题:javascript - Form validation not running onsubmit - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745550306a2662912.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论