Skip to content Skip to sidebar Skip to footer

Jquery: Call The Action's Form After Calling Preventdefault()

The code below shows an error message when a field is not filled. As you can see I'm calling preventDefault(), but...how to call the action associated to the form if the field has

Solution 1:

$('input#save').click(function(e){
  e.preventDefault()

  if($('#field_1').val() == ''){

    $('#error_file').show();

  }
  else 
  {
     $('#my_form').submit();
  }
});

Solution 2:

The issue here is where you've placed e.preventDefault(). You only want to prevent default if the validation fails, so just move it inside the if condition.

$('input#save').click(function(e){
    if($('#field_1').val() == ''){
        e.preventDefault();
        $('#error_file').show();
    }
});

Post a Comment for "Jquery: Call The Action's Form After Calling Preventdefault()"