javascript - recounting var when i delete characters -


i have script remove "disabled" attr of button when 2 vars has 3 , 5 characters respectively.

but when deleted characters doesnt count back, , add again "disabled" attr button. dont know how it. suggestions ?

fiddle: http://jsfiddle.net/ccwkp/

html

<form action="" method="" class="login">     <ul class="userlogin">         <li>             <input type="text" placeholder="e-mail" class="user" />         </li>         <li>             <input type="password" placeholder="senha" class="pass" />          </li>        </ul>     <button disabled />test</button> </form> 

js

$(function () {     var user = 0;     var pass = 0;      function userpassalert() {         if (user >= 3 && pass >=5) {             $('button').removeclass('disabled').addclass('available').removeattr("disabled");         } else {             $('button').removeclass('available').addclass('disabled').attr("disabled");         }     };      $(".user").on('focus keypress', function() {         user++;         console.log(user);         userpassalert();     });     $(".pass").on('focus keypress', function() {         pass++;         console.log(pass);         userpassalert()     });      $('button').on('click', function (e) {         e.preventdefault();         if (user >= 3 && pass >=5) {             alert("done");         }         else {            return false;          }     }); }); 

three things:

  1. to add "disabled" attribute button, has added such:

    $(".this").attr("disabled","disabled");

  2. the counter adding user/pass when there mouse click or keypress go , never down. if change check length of value in input when there mouse or key action, verify actual length existing in input field. can using:

    user=$(".user").val().length;

  3. keyup better handle backspace keypress. replacing in "on" functions provide more accurate result.

js fiddle here


Comments

Popular posts from this blog

android - Automated my builds -

how to proxy from https to http with lighttpd -

python - Flask migration error -