admin管理员组文章数量:1313806
I have a simple web form that, once the submit button has been pressed, checks to see if all required fields have data and then prints.
Here's an example of what I have so far.
<form>
<span><input value="" required=""/><label>First</label></span>
<input type="submit" name="submit" value="Submit" onclick="window.print()"/>
</form>
When a user clicks the submit button, the page is sent to the printer. Then once the page has been printed and the user returns to the page, THEN the required check is made by the browser. How can I flip these functions?
Thanks, Alex
I have a simple web form that, once the submit button has been pressed, checks to see if all required fields have data and then prints.
Here's an example of what I have so far.
<form>
<span><input value="" required=""/><label>First</label></span>
<input type="submit" name="submit" value="Submit" onclick="window.print()"/>
</form>
When a user clicks the submit button, the page is sent to the printer. Then once the page has been printed and the user returns to the page, THEN the required check is made by the browser. How can I flip these functions?
Thanks, Alex
Share Improve this question asked Oct 2, 2014 at 14:11 Alex RitterAlex Ritter 1,0413 gold badges18 silver badges44 bronze badges 3- Do you use jQuery in your project? Or are you looking for pure-JS solution to this problem? – Jevgeni Commented Oct 2, 2014 at 14:14
- Why no just write a function and call it? – Steve Commented Oct 2, 2014 at 14:14
- @jevgenig My site does use jQuery. – Alex Ritter Commented Oct 2, 2014 at 14:17
1 Answer
Reset to default 10Remove your onclick
and instead use onsubmit
on the form.
<form onsubmit="window.print();">
<span><input value="" required=""/><label>First</label></span>
<input type="submit" name="submit" value="Submit" />
</form>
本文标签: javascriptHTML Form Check requiredquotquot Before onclickquotwindowprint()quotStack Overflow
版权声明:本文标题:javascript - HTML Form Check required="" Before onclick="window.print()" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741955130a2406944.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论