mardi 30 août 2016

How do I get a function to be in effect every time something is typed in an input?

I am trying to compare the values of two input boxes, then change the border of the boxes when the value of the two boxes are not equal. The problem I am having is in the if statement where I compare the two values of the input boxes, it will never compare equal, except at the beginning where they are both blank, even if they are. I run the function through itself, I run a setTimeout on my function so it checks it every 500 milliseconds. Any help would be appreciated, and I most likely will look at the answers when I wake up in the morn.

var passContext = $('#pass').val();
var pass2Context = $('#pass2').val();

      function checkMatch() {
    if (passContext == pass2Context) {
      if($('#passCont').css({borderWidth: 1})) {
        $('#passCont').animate({
        borderWidth: 0
      }, 400)
      }
      //Add button animation
    } else {
      $('#passCont').css({
        border: '0 solid red'
      }).animate({
        borderWidth: 1
      }, 400)
      setTimeout(checkMatch, 2000);
    }
  }

  checkMatch();

Full code: http://ift.tt/2bZfUc0

Aucun commentaire:

Enregistrer un commentaire