Hi, I have a register page where there is a field for confirming the password. I have a function that evaluates if the two boxes have the same text and I call this function in the form tag, but it doesn´t work. Can someone help? Thanks in advance.

Function:
function checkPasswords() {
if (document.classic.userPassword.value!=document.classic.userPasswordChek.value) {
alert('Passwords do not match');
document.newuser.userPassword.focus();
return false;
} else {
return true;
}
}


Calling the function:

onsubmit="return checkPasswords()"

From the condition statement in the javascript function it seems that the form name is 'classic' but while setting focus you are using 'newuser'
as form name at this line
document.newuser.userPassword.focus();

This will break the javascript execution. Changing the above line to
document.classic.userPassword.focus();
might solve your problem

Thank you for your post. I have tried just now to change what you said, but unfortunately it still doesn´t work. I am not being able to solve the problem, I am running out of ideas.

Once again thank you for your post

From the condition statement in the javascript function it seems that the form name is 'classic' but while setting focus you are using 'newuser'
as form name at this line
document.newuser.userPassword.focus();

This will break the javascript execution. Changing the above line to
document.classic.userPassword.focus();
might solve your problem

Here is a sample code using the js function you have written which is working fine.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>  
 </HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function checkPasswords() {
	if (document.classic.userPassword.value!=document.classic.userPasswordChek.value) {
	alert('Passwords do not match');
	document.classic.userPassword.focus();
		return false;
	} else {
		return true;
	}
}
//-->
</SCRIPT>
 <BODY>
  <FORM METHOD=POST NAME="classic" onsubmit="return checkPasswords()">
	<INPUT TYPE="password" NAME="userPassword">
	<INPUT TYPE="password" NAME="userPasswordChek">
	<INPUT TYPE="submit">
  </FORM>
 </BODY>
</HTML>

If you could post more detailed code than it might help in finding the exact point of problem

Thank you once again, I have just solved that problem. I put it in the file where I do the INSERT of the new user, it was simpler that way, but thank you anyway for your replys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.