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
Add a ment  | 

1 Answer 1

Reset to default 10

Remove 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