Skip to content Skip to sidebar Skip to footer

Jquery Validate And Send Form With A Link

This is my code:

Solution 1:

Without a submit button you need to check the form is valid manually.

Firstly, remove the onclick attribute from your HTML - this is not a good method of attaching events.

<a href="#"id="button" class="button">Send</a>

Then place this in your jQuery code:

$("#button").click(function() {
    if ($("#alta").valid()) {
        $("#alta").submit();
    }
});

Solution 2:

inside the click handler validate the form.

   $("#button").click(function(e){
    e.preventDefault();
    if($("#alta").valid()){
        //submit
        $("#alta").submit();
    } 
    elsereturnfalse;
  });

also (after reading the comments) you dont need to validate the form in document ready

Post a Comment for "Jquery Validate And Send Form With A Link"