Rahul Singh
Rahul Singh

Reputation: 1632

Jquery issues returning true

I am creating a form using AJAX. ON particular conditions I have return false and finally I returned true...

$('#addalbum').submit(function(e) {
    e.preventDefault();

       if(!chk Conditions){
          return false; 

          }
       else
       return true;
   alert("Sankalp after return");
});

Though If conditions are going good. But its not returning true condition as my page is not refreshing in case if all conditions are true.

Upvotes: 0

Views: 46

Answers (1)

Grant Thomas
Grant Thomas

Reputation: 45083

You don't have any conditions in the specified code (not to mention that return true is commented out and so is useless here anyway), but if you did, then it might look a little something likethis:

$('#addalbum').submit(function(e) {
  if (yourCondition) {
    return true;
  }
  e.preventDefault();
  return false;
});

What you're doing right now is preventing the default behaviour (which would be to submit the form) regardless of the outcome of anything else.

EDIT per your update and comment:

You are still preventing the default behaviour, essentially discarding the result of anything else - the form won't submit if you e.preventDefault, so only do this if your condition isn't met, not first thing.

Upvotes: 3

Related Questions