Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit a form with jQuery / Javascript without ignoring "required" tag

so I have the following form:

    <form action="register.php" method="post" id="register-form" name="register-form">
    <input type="text" id="username" name="username" placeholder="Username" autofocus="autofocus" required />
    <input type="text" id="password" name="password" placeholder="Password" required />
    <a href="javascript:void(0);" class="btn" onclick="$('#register-form').submit();">Register</a>
    <input type="submit" style="display: none;" />
    </form>

What I want to know, is there a way to make jQuery take care of the "required" tag when submitting a form? Right now it doesn't.

like image 407
Jonas Kaufmann Avatar asked Jan 30 '26 00:01

Jonas Kaufmann


1 Answers

Trigger click on the submit button instead.

http://jsfiddle.net/PdUcq/

like image 168
Explosion Pills Avatar answered Feb 01 '26 15:02

Explosion Pills



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!