0
<input id="checkOldPassword" type="button" title="Check New Password" value="Check New Password" onclick="checkPassword()" />
<input id="newPassword" type="text" maxlength="8" min="8" />

<script language="javascript">
function checkPassword()
{
  var validString = /^[a-z](?=[a-z]*[0-9])[a-z0-9]{0,6}[a-z]$/;
  alert("this worked");
  var password = document.getElementById(newPassword).value;
  alert(password);
  var test = re.test(password);
}
</script>

The popup window saying "this worked" appears correctly so I know the code is executing but alert(password) doesn't pop up the typed password. What am i doing wrong?

2 Answers 2

2

Change...

var password = document.getElementById(newPassword).value;

To (note the quotes on the element id)...

var password = document.getElementById("newPassword").value;
Sign up to request clarification or add additional context in comments.

Comments

1

Use quotes:

document.getElementById('newPassword').value

Without quotes you have:

document.getElementById(undefined)

as you don't have any newPassword variable defined.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.