I have an <input> text field where user can type his password.
in this <input> tag i have an onkeypress function which execute a javascript function.
this js function check the number of characters typed. But there is a little issue.
when user has type the 2nd character, the function detect only 1 character.
...
when user has type 10 characters, the function detect only 9 characters.
It's like the latest typed character is never sent to my js function.
here after you can find a sample.
thanks a lot,
M.
// in my PHP page
<INPUT class='box600_form_field_text' TYPE='password' id='field_newpwd2' name='my_newpwd2' value='' onkeypress='CheckPwdStrength(this.value, \"pwd_img_strength\");'></INPUT>
// my js function
function CheckPwdStrength(pwd, image_id)
{
// get object of image
bargraph = document.getElementById(image_id);
if(pwd.length >= 8) // strong
{
// check if uppercase / lower case
// check if number
}
else if (pwd.length >= 6) // average
{
bargraph.src='../../images/icon/yellowpwd_analyzer.gif';
}
else if (pwd.length >= 4) // weak
{
bargraph.src='../../images/icon/orangepwd_analyzer.gif';
}
else if (pwd.length <4) // very weak
{
bargraph.src='../../images/icon/redpwd_analyzer.gif';
}
- user presses a key
-* onkeydown event fires (this includes keys like shift and alt-f4)
- onkeypress event fires (alphanumeric keys, stuff that would actually change the textbox)
- character gets added to textbox
- if user holds down key, goto *
- user lets go of key
- onkeyup event fires
Note that from the onkeypress function you can get the value of the key being pressed from the event object.
Bookmarks