diff options
-rw-r--r-- | csci4131/hw2/strap012/passwordcheck.js | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/csci4131/hw2/strap012/passwordcheck.js b/csci4131/hw2/strap012/passwordcheck.js index 53e9b3f..97a2918 100644 --- a/csci4131/hw2/strap012/passwordcheck.js +++ b/csci4131/hw2/strap012/passwordcheck.js @@ -1,16 +1,16 @@ -var input = document.getElementById("password"); +var input; var result = document.querySelector("span"); -// result.onload = function() {setResult()}; -// function setResult() { -// result = document.querySelector("span"); -// } +window.addEventListener('DOMContentLoaded', (event) => { + input = document.getElementsByName("password")[0]; +}); function checkStrength() { - var password = document.getElementById("password").value; + var password = input.value; var strength = 0; if (password.length < 6) { result.removeAttribute("class"); result.classList.add('short'); result.innerHTML = "Too short"; + return; } if (password.length > 7) { strength += 1;} // If password contains both lower and uppercase characters, increase strength value. @@ -27,13 +27,16 @@ function checkStrength() { result.removeAttribute("class"); result.classList.add('weak'); result.innerHTML = 'Weak'; + return; } else if (strength == 2) { result.removeAttribute("class"); result.classList.add('good'); result.innerHTML = 'Good'; + return; } else { result.removeAttribute("class"); result.classList.add('strong'); result.innerHTML = 'Strong'; + return; } } |