View Full Version : Problem in javacript code ?????

06-25-2009, 02:44 PM
Hi all,

I have made to select box in which one is adult and other is for child .
adult select box have 1 to 10 numeric value and child have 1 to 10 numeric value.

but now i want to make if both of select box total is greater than 10 then it will give alert that Total adult and child can not be greater than 10 and it will return false.

i have used this javascript code for this

var tot=document.form1.adult.value + document.form1.child.value ;
if (tot >= "10")
alert ("Total value can not be greater than 10");
return false;

Here like adult have value 4 and child have value 8 then tot should show
12 but it is showing 48 .

So how i can show this as a sum tot
my means how i can show value 12 for this.

06-25-2009, 02:53 PM
var tot=parseInt(document.form1.adult.value) + parseInt(document.form1.child.value) ;

if (tot >= 10)

06-25-2009, 02:57 PM
errm ... over 4 years since I last wrote Java scripts ... why im having trouble with my own :S

But ... your line "var tot=document.form1.adult.value + document.form1.child.value ;" isn't that a concatination? From memory that it is taking the value for adult and the value for child and displaying them together as a single string.

I'm thinking you would have to convert the values to Integers first, then do the calculations, then have the new total display.