Control which submit button the jQuery form validation plugin fires with

Consider the following form.

<form>
<input type="text" name="mytext" />
<button type="submit" name="next">next</button>
<button type="submit" name="back">back</button>
</form>

In this case, we only want the jQuery validation plugin to do its thing when the ‘next’ button is clicked. If the back button is clicked we do not care about the validation.

The solution is simple. Add the CSS class ‘cancel’ to the back button.

<button type="submit" name="back" class="cancel">back</button>

I couldn’t find this in the online docs. So hence this post.

2 thoughts on “Control which submit button the jQuery form validation plugin fires with

  1. Thanks, this is exactly what I was looking for.

    I was about to go wrapping the validate in something like $(“#next_button_id”).click(function(){ …, but this works much better.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>