返回空白消息,需要 document.getElementById 异常
我有一个表单,但有一个例外,当用户没有填写文本框并单击“提交”时,它会发送一封空白电子邮件。我想做的是,如果用户单击“提交”并且表单为空白,则会弹出一条消息(在新窗口或同一窗口中,无关紧要),要求他们在提交之前填写表单。总体而言,目标是不发送空白电子邮件。
HTML 按钮代码如下:
<a href="#" class="SubBtn" onclick="document.getElementById('form').submit()">Submit</a>
<a href="#" class="ResBtn" onclick="document.getElementById('form').reset()">Reset</a>
我不确定在这种情况下是否需要异常处理,或者 javascript 是否可以正确修复。或者如果有除此之外的简单修复方法,请帮忙。
I have a form that works with one exception, when a user doesn't fill out the text boxes and click submits it sends a blank email. What I would like to do is if the user clicks submit and the form is blank, have a message popup (in a new window or same, doesn't matter) that requires them to fill out the form prior to submitting. Overall, the goal is to not have a blank email sent.
The HTML button code is as follows:
<a href="#" class="SubBtn" onclick="document.getElementById('form').submit()">Submit</a>
<a href="#" class="ResBtn" onclick="document.getElementById('form').reset()">Reset</a>
I'm not sure if there needs to be exception handling in this situation, or if it a javascript would be a proper fix. Or if there is a simple fix beyond that, please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了完成这一切,需要一个 JavaScript 验证函数。
,它将显示如何对空字段以及电子邮件字段(我提供有效的电子邮件地址进行验证)进行操作。
这里有一个链接 rel="nofollow">http://www.w3schools.com/jS/js_form_validation.asp
To accomplish this all that is needed, is a javascript validation function.
Here is a link that will show how it is done for empty fields as well as email fields (where a valid email address me present to validate.)
http://www.w3schools.com/jS/js_form_validation.asp