Click to See Complete Forum and Search --> : Comparing Numbers


sivaprasad
03-17-2003, 11:42 AM
Hi,
Can anyone tell me how to solve the following problem using Javascript.
I have to compare 2 numbers entered by the user in to two textboxes.i.e,
1.To check the textboxes are null
2.To check the string entered is number.(in both the text boxes)
3.To check greater number among the two.

Note:Javascript on "onSubmit" method pls.

thanks in advance
SP.

khalidali63
03-17-2003, 11:49 AM
Presuming that the form has two text fields
t1 and t2

var t1Val = document.formName.t1.value;

var t2Val = document.formName.t2.value;

//confirm that both values are number

var numA=0,numB=0;

if(isNaN(parseInt(t1Val)){
alert("Text 1 field 1 has non number value")
}else{
numA = parseInt(t1Val);
}

if(isNaN(parseInt(t2Val)){
alert("Text 1 field 1 has non number value")
}else{
numB = parseInt(t2Val);
}

At this point you can use less then or greater then expressions to find out which number is < or >

hope this helps

Cheers

Khalid

sivaprasad
03-18-2003, 06:08 AM
Hi,
I got my problem solved...,
anyway Thank you

Regards
SP