Skip to content Skip to sidebar Skip to footer

Form Submit With 2 Different Errors Depending On Input Value - 1 Is Not Working

I posted a question on how to make 2 errors work here: Multipile forms with input and submit button with the same action with Javascript I needed 2 errors, 1 error if the input if

Solution 1:

This is how I would do this. Try to avoid using too many nested if statments. Instead create the escape clauses with return statements when the user enters the incorrect value first.

$('form#unlock1').on('submit', function(){
  var $el = $('form#unlock1 > input.the_imei');

  if($el.val().length<15){
    //Not enough characters
    return false;
  }

  if($el.val().substring(0,4)=='9900') {
    //Value begins with 9900
    return false;
  }

  //User has entered a correct imei
});

Post a Comment for "Form Submit With 2 Different Errors Depending On Input Value - 1 Is Not Working"