1

I am using this amazing script for validating my form and for the normal functionality it works great, but I would like to validate the form on a onClick (a href) event instead on the submit (input).. is that possible?

Script: https://github.com/jzaefferer/jquery-validation

It must be something like this, right?

<a href="#" onClick="validate()" >
0

2 Answers 2

6

You can call the valid() method on the form to see whether it is valid.

<a href="#" onClick="$('myformselecto').valid()" >

I would recommend adding the handler using jQuery rather than inlining it

Sign up to request clarification or add additional context in comments.

1 Comment

This works great, thank you. I made it using jquery: $('#divid').click(function(e) { e.preventDefault(); $('form').valid(); });, but is it also possible to go to a div (#divid2) when valid?
1

The jQuery validation plugin hooks to the submit event of the form. Therefore all you need to do is make the click of that a element submit the form. Try this:

$('#myLink').click(function(e) {
    e.preventDefault();
    $('#myForm').submit(); // this will then call the validate() func
});

2 Comments

Thanks for the quick answer! But I don't want to submit the form yet, that has to be done later on the page, I first want to validate and use a input submit to submit the form later on :)
Ah ok, no problem. Arun has the answer for you then :) But like he says, don't use the onclick attribute - attach your events in jQuery itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.