woolyg Posted December 12, 2007 Share Posted December 12, 2007 Hi all, my first post here - hope someone can help. I'm trying to put together an AJAX-based form validation (still learning) and I'm stuck trying to get the form to tell the user when their passwords do not match. Everything else on the form uses AJAX to validate the input, but I just can't get the program to check when password1 != password2. Heres my main code (please assume that my connections to DB and other ajax xhr requests work fine otherwise, and my styles.CSS holds div ID info) - is there a problem with my javascripting? <?php require "../inc/session.php"; // Include the Sajax library include "../inc/Sajax2.php"; // Function to check if passwords match function check_passwordsmatch() { $password1 = mysql_escape_string($password1); $password2 = mysql_escape_string($password2); if ($password1 != $password2){ // PW not OK return array('no'); } // PW OK return array('yes'); } ?> <!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>Sign Up!</title> <script type="text/javascript"> <?php sajax_show_javascript(); ?> function check_passwordsmatch(result) { if(result[0] == 'yes') { document.getElementById('pw_no_match').style.display = 'none'; document.getElementById('pw_match').style.display = 'block'; } if(result[0] == 'no') { document.getElementById('pw_match').style.display = 'none'; document.getElementById('pw_no_match').style.display = 'block'; var str = 'The passwords you have entered do not match. please try again.'; document.getElementById('pw_no_match').innerHTML = str; } } function passwordsmatch() { var password1 = document.getElementById('password1').value; var password2 = document.getElementById('password2').value; x_passwordsmatch(password1, password2, check_passwordsmatch); } </script> <link href="../inc/styles.css" rel="stylesheet" type="text/css" /> </head> <body> <table class="signup"> <tr> <td class="signupleft">Password:</td><td class="signupright"><input type="text" name="password1" id="password1" size="20" maxlength="32" class="boxes" /></td> </tr> <tr> <td class="signupleft">Verify Password:</td><td class="signupright"><input type="text" name="password2" id="password2" size="20" maxlength="32" class="boxes" onBlur="check_passwordsmatch(); return false;" /><div id="pw_no_match">no</div><div id="pw_match">yes</div></td> </tr> </table> </body> </html> All help appreciated. Woolyg. Quote Link to comment Share on other sites More sharing options...
djbuddhi Posted March 11, 2008 Share Posted March 11, 2008 where is the sajax2.php 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.