xdarkinsidex
12-06-2010, 01:01 AM
Hi there! I'm completely new to javascript coding, but have suddenly found myself in need of using it. here's a little background (helps me keep track of where I am in my question).
I've been "playing" with php for quite a while, and I decided I wanted to see how hard it would be to code a fairly simple forum. So far, everything is working out with very little need for bug fixes and some efficiency suggestins from a friend.
I'm currently building the registration page, and wanted to have it compare the password and verification while the form is being filled. I found a code to do it after a few searches, but evidently I am missing something about how it works.
This is the code I found:
<script type='text/javascript'>
function comparePasswords()
{
if(document.getElementById('pass1').value != document.getElementById('pass2').value)
{
$('passwordShow').innerHTML = 'Passwords do not match';
}
else
{
$('passwordShow').innerHTML = '';
}
}
</script>
This is the full code for the form I am trying to use it in:
<?php
echo "<script type='text/javascript'>\n function comparePasswords()\n {\n if(document.getElementById";
echo "('pass1').value != document.getElementById('pass2').value)\n {\n $('passwordShow').innerHTML";
echo " = 'Passwords do not match';\n }\n else\n {\n $('passwordShow').innerHTML = '';\n";
echo " }\n }\n</script> ";
echo "<form action='index.php?pg=verify' method='post'>";
echo "<table align='center' style='color: #C0C0C0'>";
echo "<tr><td>Username:</td><td><input type='text' name='user' /></td></tr>";
echo "<tr><td>Password:</td><td><input type='password' name='pass1' /></td></tr>";
echo "<tr><td>Re-enter Password</td><td><input type='password' name='pass2' onkeyup='comparePasswords();' /></td></tr>";
echo "<tr><td>Email<br />(used for password recovery)</td><td><input type='text' name='email' /></td></tr>";
require ('questions.php');
echo "<input type='hidden' name='source' value='reg' />";
echo "<br><center><input type='submit'/></form>";
?>
What am I not understanding about this?
I've been "playing" with php for quite a while, and I decided I wanted to see how hard it would be to code a fairly simple forum. So far, everything is working out with very little need for bug fixes and some efficiency suggestins from a friend.
I'm currently building the registration page, and wanted to have it compare the password and verification while the form is being filled. I found a code to do it after a few searches, but evidently I am missing something about how it works.
This is the code I found:
<script type='text/javascript'>
function comparePasswords()
{
if(document.getElementById('pass1').value != document.getElementById('pass2').value)
{
$('passwordShow').innerHTML = 'Passwords do not match';
}
else
{
$('passwordShow').innerHTML = '';
}
}
</script>
This is the full code for the form I am trying to use it in:
<?php
echo "<script type='text/javascript'>\n function comparePasswords()\n {\n if(document.getElementById";
echo "('pass1').value != document.getElementById('pass2').value)\n {\n $('passwordShow').innerHTML";
echo " = 'Passwords do not match';\n }\n else\n {\n $('passwordShow').innerHTML = '';\n";
echo " }\n }\n</script> ";
echo "<form action='index.php?pg=verify' method='post'>";
echo "<table align='center' style='color: #C0C0C0'>";
echo "<tr><td>Username:</td><td><input type='text' name='user' /></td></tr>";
echo "<tr><td>Password:</td><td><input type='password' name='pass1' /></td></tr>";
echo "<tr><td>Re-enter Password</td><td><input type='password' name='pass2' onkeyup='comparePasswords();' /></td></tr>";
echo "<tr><td>Email<br />(used for password recovery)</td><td><input type='text' name='email' /></td></tr>";
require ('questions.php');
echo "<input type='hidden' name='source' value='reg' />";
echo "<br><center><input type='submit'/></form>";
?>
What am I not understanding about this?