I am working on a regular expression to check the password field, Now the javascript that tests the varible is working, but when I try to call it and check the form I can’t seem to get the javascript to see that I want it to check the password in the form with the javascript I made but I can’t seem to get the form to commnuicate with the javascript I made, The form and the javascript are on the same page, what I want for it to do is after it checks the password requirements it will just go and submit the form. Here is what I have so far.
<html>
<body>
<script type="text/javascript">
function checkPassword(password)
{
password = document.getElementById('thethePasswordFieldField').value;
var patt=/[a-z]/g;
var patt2 = /[A-Z]/g;
var patt3 = /[0-9]/g;
var patt4 = /[~\!@#\$%\^&*_\-\+=`\|\\(\)\{\}\[\]:;"'<>,\.\?\/]/g;
var result=patt.test(password);
var result2=patt2.test(password);
var result3=patt3.test(password);
var result4=patt4.test(password);
if (!result)
alert("Needs a lowercase & uppercase letter, a number & a special character.");
if (!result2)
alert("Needs a lowercase & uppercase letter, a number & a special character.");
if (!result3)
alert("Needs a lowercase & uppercase letter, a number & a special character.");
if (!result4)
alert("Needs a lowercase & uppercase letter, a number & a special character.");
if (result && result2 && result3 && result4)
alert("");
document.getElementById('frmApplication').submit();
}
</script>
<form id="frmApplication" name="frmApplication" action="test.html" method="post">
Password: <input type="text" name="thethePasswordFieldField" id="thethePasswordFieldField">
<a href="javascript:checkPassword()">Submit</a>
</form>
</body>
</html>
You’re using
getElementByIdbut have not actually assigned an ID attribute to the “password” field.Try:
The reason I suggest using this convention is to avoid using “password” as your actual field name (IE will probably die if you use this method) and to also of course, actually use a
passwordtype field.Hopefully it should be obvious to you that your initial
getElementByIdline must refer to the “thePasswordField” ID value.I have not vetted the rest of your code, but put the ID attribute in there and give it a shot.