|
I want to write a simple function to compare a password with the confirmation password that the user provides. I want to create a simple function to make sure that the code works before I connect the code to the database. I am hard coding teh values in the variables to do this. I need to pass the two parameters to the function. Here is the code that i have written: -
<html>
<head>
</head>
<script language="javascript">
var password = "pass1";
var confirmPassword = "pass1";
function doFieldsMatch( password, confirmPassword)
{
if (password == confirmPassword) {
alert('Same Values')
return true;
}
else {
alert( 'Do not match');
return false;
}
}
</script>
<body>
<form id=myForm name=myForm action="/forum/someform.html" method="post">
<input type=submit value="Submit" onClick="doFieldsMatch('password', 'confirmPassword')">
</form>
</body>
</form>
Whatever values I set the variables to, the 'Do not match' option is always displayed.
Does anyone know what I am doing wrong?
All suggestions will be welcome.
|
|
|
I copied your code exactly into a new HTML file. I opened it in my browser, clicked the submit button, and got the message "Do not match".
I then changed the call to the function to pass the same value for both parameters. Then I reloaded the page and pressed the submit button. I got the message "Same Values".
Your code appears to work to me. I do see one simple mistake. The last tag should be "</html>". Instead, you have a second "</form>".
|
|
|
|
|
|
|
|
|
|