Div toggled onKeyup and stays visible Javascript and JQuery

netknave

New Member
here is my problem :I am currently designing a JavaScript function destined to verify the safety level of a password. Once the password is typed, I use jQuery to toggle the display of a div (which is invisible by default) which contains the sentence "Your password is" + the given level of safety. Everything works fine, except that I use the \[code\]onKeyUp event\[/code\] in the password-input to trigger my div appearing. However, naturally, every key pressed toggles the visibility of my div. Result: with every first key pressed in the password input, my div appears, with the next key pressed, it disappears again. Is there a way to toggle the div once with the first key pressed and prevent it from disappearing with pressing of the next key ?Here is the code :\[code\]function password1Security(){ var pwd1 = document.getElementById("password1"); var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g"); var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g"); var pwdsft = document.getElementById("passwordSafetyLevel1"); { if (strongRegex.test(pwd1.value)) { pwdsft.innerHTML = '<span style="color:green;">Safe</span>' } else if (mediumRegex.test(pwd1.value)) { pwdsft.innerHTML = '<span style="color:eek:range;">Quite Safe</span>' } else { pwdsft.innerHTML = '<span style="color:red;">Unsafe</span>' }; }};<input name="password1" id="password1" type="password" size="15" maxlength="20" style="width:500px; height:30px;" onKeyUp="showPassSafety1()" /><br/><span name="passwordSafety1" id="passwordSafety1" style="font-size:12pt; display:none;">Your password is <b name="passwordSafetyLevel1" id="passwordSafetyLevel1"></b>.< /span><br/>\[/code\]
 
Top