Jump to content

Password field checks don't run.


pakenney38

Recommended Posts

Here's a code snippet from something I am working on.
The problem is that my JavaScript function doesn't seem to run at all when the page is pulled up in the browser.

[code]echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
<title>Set up email</title>
<script type='text/javascript'>
<!--
function passcheck(Form1) {
if (Form1.Password.value.length < 6)
{alert('The password must contain at least 6 characters.');
return false;}
else {
if (Form1.Password.value.indexOf('XXX') > -1)
{alert (\"The password you have entered violates\none or more of the following rules:\n
  1. The password must be 6 or more characters long.\n
  2. The password cannot contain XXX.\n
  3. The password cannot contain the word password.\n
  Please choose another password.\");
  return false;}
else {
if (Form1.Password.value.indexOf('password') > -1)
{alert (\"The password you have entered violates\none or more of the following rules:\n
    1. The password must be 6 or more characters long.\n
          2. The password cannot contain XXX.\n
          3. The password cannot contain the word password.\n
          Please choose another password.\");
          return false;}
else {
if (Form1.Password.value.indexOf(' ') > -1)
{alert (\"The password cannot contain any spaces.\n
  Please choose another password.\");
  return false;}
else {
return true;}}}}}

//-->
</script>
</head>
<html>
<body>
<p><img src='login-window_logo.gif' width='188' height='60'>";

if (strlen($sMsg) > 0) {
echo($sMsg . "<br />");
}

if (strlen($sErr) > 0) {
echo($sErr . "<br />");
}

    echo "</p>
<p><strong>Please enter a password to be used for your new account.<br>
This password must be 6 or more charaters long.<br>
The password cannot contain 'XXX'.<br>
The password cannot contain the word 'password'.</strong></p>
<form method='post' name='Form1' onSubmit='return passcheck(this)' action='{$_SERVER['PHP_SELF']}'>
Postoffice:
  <input type='text' name='PostOffice' value='XXX' readonly />
  <br />
Mailbox name: <input type='text' name='MailBox' value='$mailbox' readonly /><br />
Password: <input type='password' name='Password' value='$Password' /><br />
<input type='hidden' name='TRANS' value='1' />
<input type='submit' value='Add Mailbox' />
</form>
</body>
</html>";[/code]
Link to comment
Share on other sites

No need to be rude. The PHP portion of the source code is working properly -- so the problem isn't PHP. The javascript part of your source code is not working properly, so you got moved to the javascript forum. The moderator did you a favor by putting your post where it would get the fastest answer.

Now, the problem your javascript is having: "unterminated string literal." That means if you put a newline in a javascript string, then the string won't terminate.

Your source code has two different types of newlines that are causing this to happen:
1. your \n character is being converted to a newline by PHP. To eliminate this, you need to escape your backslash .. like so "\\n". This tells PHP to not convert \n to a newline character, but pass it "as is" to the browser. First problem overcome.
2. Your source code also contains newline characters. Look here -- after the \n you are putting a carriage return in the source code to "pretty it up."
[quote]{alert (\"The password you have entered violates\none or more of the following rules:\n
  1. The password must be 6 or more characters long.\n[/quote]
This is causing the other half of your problem. Delete that carriage return and you're back in business.

After I fixed or removed the two different types of newline characters, "poof" your code works just fine.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.