Compare two (2) form values and see if they're the same (Rated 0)Description:
In this example it simply displays an alert, whereas in reality you'd want to only display to the alert if there is an error. Code starts here
<script>
function compare(valOne, valTwo)
{
if (valOne != valTwo)
{
alert("Your passwords must match");
return false;
}
else
{
alert("Your passwords match - well done");
return false;
/*Comment out the two line above and uncomment the one below to actually submit the form*/
//return true;
}
</script>
<form action="page2.html" name="myForm">
<input type="text" name="passwordOne"><br><br>
<input type="text" name="passwordTwo"><br><br>
<input type="submit" onClick="JavaScript: return compare(myForm.passwordOne.value,myForm.passwordTwo.value); return false;">
</form>
Submitted by MattK on 06-01-2006 8:39 |