SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Nov 24, 2006, 14:23 #1
- Join Date
- Feb 2006
- Posts
- 168
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
password strength works fine on firefox but not IE, help please
Here is my code, it works perfect on Firefox but not at all on IE. If you can help it would be appreciated.
Code:var giTest = 0; function passStrength() { var iTest = 0; var strInput = $F('password'); if (strInput.length > 5) {iTest++;} if (strInput.match(/[A-Z]/)) {iTest++;} if (strInput.match(/[0-9]/)) {iTest++;} for (var i = 0; i <= strInput.length;i++) { if (strInput.charCodeAt(i) >= 33 && strInput.charCodeAt(i) <= 47) {iTest++; break;} } if (strInput.length <= 5) {iTest = 0;} switch (iTest) { case 0: if (iTest < giTest){document.getElementById('pStrength').style.backgroundColor = '#ff9999';} case 1: if (giTest < iTest) { document.getElementById('pStrength').style.backgroundColor = '#ffbf99'; } else if (iTest < giTest) { document.getElementById('pStrength').style.backgroundColor = '#ff9999'; } break; case 2: if (giTest < iTest) { document.getElementById('pStrength').style.backgroundColor = '#fff499'; } else if (iTest < giTest) { document.getElementById('pStrength').style.backgroundColor = '#ffbf99'; } break; case 3: if (giTest < iTest) { document.getElementById('pStrength').style.backgroundColor = '#f2ff99'; } else if (iTest < giTest) { document.getElementById('pStrength').style.backgroundColor = '#fff499'; } break; case 4: if (giTest < iTest) { document.getElementById('pStrength').style.backgroundColor = '#a5ff99'; } else if (iTest < giTest) { document.getElementById('pStrength').style.backgroundColor = '#f2ff99'; } break; } giTest = iTest; }
-
Nov 25, 2006, 15:11 #2
- Join Date
- Feb 2006
- Posts
- 168
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Wow, I thought this would be an easy answer for most of you guys. But seems to have even the pros stumped.
-
Nov 30, 2006, 07:08 #3
- Join Date
- Feb 2006
- Posts
- 168
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
last try, anyone??
-
Nov 30, 2006, 07:29 #4
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You provided neither the example code (what is 'pStrength'? how do you call your function?) nor did you describe your problem ("it doesn't work" is not a description). No wonder that noone replied.
-
Dec 5, 2006, 16:06 #5
- Join Date
- Feb 2006
- Posts
- 168
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No problem.
This is a script to test the strength of a password, after each key up event in a password input it runs this function to test the strength and then depending on the results of the test it changes the background-color of a div to reflect. Red is bad green is good type of a thing.
pStrength is a password input.
The function is called by onkeyup="passStrength();"
And as far as the problem, well I don't knwo how else to describe it. Like I said it works fine in Fire Fox however in IE nothing happens.
Sorry stereofrog I just presumed that the above were all common sense from looking at the code. One day I will learn to stop presuming, always gets me into trouble
If you or anyone else could it would be greatly appreciated. Thanks
-
Dec 5, 2006, 16:32 #6
Try this: (reformatted for me)
Code:var giTest = 0; function passStrength() { var iTest = 0; //var strInput = $F('password'); var strInput = document.getElementById('pStrength'); if (strInput.value.length > 5) { iTest++; } if (strInput.value.match(/[A-Z]/)) { iTest++; } if (strInput.value.match(/[0-9]/)) { iTest++; } for (var i = 0; i <= strInput.value.length;i++) { if (strInput.value.charCodeAt(i) >= 33 && strInput.value.charCodeAt(i) <= 47) { iTest++; break; } } if (strInput.value.length <= 5) { iTest = 0; } switch (iTest) { case 0: if (iTest < giTest) { strInput.style.backgroundColor = '#ff9999'; } break; case 1: if (giTest < iTest) { strInput.style.backgroundColor = '#ffbf99'; } else if (iTest < giTest) { strInput.style.backgroundColor = '#ff9999'; } break; case 2: if (giTest < iTest) { strInput.style.backgroundColor = '#fff499'; } else if (iTest < giTest) { strInput.style.backgroundColor = '#ffbf99'; } break; case 3: if (giTest < iTest) { strInput.style.backgroundColor = '#f2ff99'; } else if (iTest < giTest) { strInput.style.backgroundColor = '#fff499'; } break; case 4: if (giTest < iTest) { strInput.style.backgroundColor = '#a5ff99'; } else if (iTest < giTest) { strInput.style.backgroundColor = '#f2ff99'; } break; } giTest = iTest; }
Bookmarks