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
https://forums.phpfreaks.com/topic/81309-password-matching-using-the-jax/
Share on other sites

  • 2 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.