pakenney38 Posted December 28, 2006 Share Posted December 28, 2006 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] Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 28, 2006 Share Posted December 28, 2006 Do you have the if post submit statement? because I cant seem to find it on your script, that might be the cause...Ted Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 28, 2006 Share Posted December 28, 2006 This is a Javascript question, not a PHP question, so I will move it to the Javascript section.Ken Quote Link to comment Share on other sites More sharing options...
pakenney38 Posted December 28, 2006 Author Share Posted December 28, 2006 I will be more than happy to rewrite this code in PHP where it will be twice as difficult to write and then repost it back into a forum that actually gets looked at. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted December 30, 2006 Share Posted December 30, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.