View Full Version : Form validation

08-23-2002, 12:23 PM
Hi All

I need a help on client side validation. I have several textboxes in my form, and I want to add(sum) the content of two textboxes and store it in a variable. I want the content of that variable to be compared ( > OR <) than the third textbox. If yes then the form should not be submitetd.


08-23-2002, 02:14 PM
hope this helps


<title>sum test</title>

function checkSum() {
var num1 = document.myForm.firstNumber.value;
var num2 = document.myForm.secondNumber.value;
var comp = document.myForm.compareNumber.value;
if( isNaN(num1) || isNaN(num2) || isNaN(comp) || num1.length<1 || num2.length<1 || comp.length<1 ) {
alert( 'error: all fields must have a numeric value' );
return false;

if( parseInt(num1) + parseInt(num2) == parseInt(comp) ) {
alert( 'ok to submit' );
return true;
else {
alert( 'cannot submit' );
return false;

<body bgcolor="#FFFFFF" text="#000000">
<form name="myForm" action="myPage.html" method="post" onSubmit="return checkSum()">
first number:<br><input type="text" name="firstNumber" maxlength="10" value="0"><br><br>
second number:<br><input type="text" name="secondNumber" maxlength="10" value="0"><br><br>
compare number:<br>
<input type="text" name="compareNumber" value="0"><br><br>
<input type="submit" name="myButton" value="submit">

08-26-2002, 11:32 AM
Hi Tommy Cooper,

Thanks it works