| Code: |
|
var minpwlength = 6; var maxpwlegnth = 30; var STRENGTH_SHORT = 0; var STRENGTH_WEAK = 1; var STRENGTH_FAIR = 2; var STRENGTH_STRONG = 3; img0 = new Image(); img1 = new Image(); img2 = new Image(); img3 = new Image(); img0.src = 'pw_too_short.png'; img1.src = 'pw_fair.png'; img2.src = 'pw_medium.png'; img3.src = 'pw_strong.png'; var strengthlevel = 0; var strengthimages = Array(img0.src, img1.src, img2.src, img3.sr); function updatestrength(pw) { if( istoosmall(pw)){ strengthlevel = STRENGTH_SHORT; } else if( !isfair(pw)){ strengthlevel = STRENGTH_WEAK; } else if( hasnum(pw)){ strengthlevel = STRENGTH_STRONG; } else { strengthlevel = STRENGTH_FAIR; } document.getElementById('strength').src = strengthimages[ strengthlevel ]; } function isfair(pw){ if(pw.length < fairpwlength){ return false; } else { return true; } } function istoosmall(pw){ if(pw.length < minpwlength){ return true; } else { return false; } } function hasnum(pw){ var hasnum = false; for(var counter = 0; counter < pw.length; counter ++){ if(!isNaN(pw.charAt(counter))){ hasnum = true; } } return hasnum; } |
this script was meant to show how strong a user's password is when they choose one for the forum in my site. depending on the number of characters, it displayed a picture. but the problem is tht there is an error when i input something into the password field. it says tht the function i'm calling is undefined.
the code for the html page is below:
| Code: |
|
<body onload="document.getElementById( 'password' ).focus();"> <div>Enter your password here:</div> <br /> <div> <input maxlength="15" onkeyup="updatestrength( this.value );" type="password" name="password" id="password" value="" /> <img src="images/tooshort.jpg" id="strength" alt="" /> </div> </body> |
