Jump to content

Password-matching using the 'jax?


woolyg

Recommended Posts

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.

Link to comment
Share on other sites

  • 2 months later...
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.