0

I am having an form in a swipe slider, and I am using the following script to check if my form is valid without a submit because I want to input submit it in another slide:

$('#divId').click(function(e) { e.preventDefault(); $('form').valid(); });

That works great but now I would like to trigger the swipe onClick event only if the validation is correct:

<a href="#" onClick="mySwiper.swipeTo(1, 10)">

Is there an easy way to achieve this?
If valid(); = ok THEN onClick="mySwiper.swipeTo(1, 10)

Scripts:
https://github.com/jzaefferer/jquery-validation
http://www.idangero.us/sliders/swiper/

Other Stack:
jQuery Validation on click without submit

2 Answers 2

1

You could use the return value of valid() and put this in an 'if` statement.

$('#divId').click(function(e) { 
   e.preventDefault(); 
   if ($('form').valid()){
     mySwiper.swipeTo(1, 10);
   } 
});
Sign up to request clarification or add additional context in comments.

Comments

0

why not try like this:

$('#divId').click(function(e) { 
     e.preventDefault(); 
     $('form').valid(); 

     // your validation check goes here
     if( vadiation_pass ) {
         $('#link').attr("onClick", "mySwiper.swipeTo(1, 10)");
     } else {
         $('#link').removeAttr('onClick');
     }
});

// HTML
<a href="#" id="link">

Comments

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.