Control sum from input boxes in javascript -


i'm trying make controls in javascript when submit form in html.

evertyhing works except 1 needs check sum of 2 fields.

<script type="text/javascript"> function validation() { var count=0; if((document.getelementsbyname("people")[0].selectedindex) == "")     {alert("how many people?"); count++;} else if((document.getelementsbyname("amount")[0].selectedindex) == "")     {alert("amount has @ least 1."); count++;} else if((document.getelementsbyname("deposit")[0].value) == "")     {alert("deposit cannot empty."); count++;} else if((document.getelementsbyname("deposit")[0].value) < "20")     {alert("deposit must @ least 20."); count++;} else if((document.getelementsbyname("topay")[0].value) == "")     {alert("mark 0 in pay if dont have pay more."); count++;} else if( (  (document.getelementsbyname("deposit")[0].value) + (document.getelementsbyname("topay")[0].value) ) < "40")     {alert("the minimum price of product 40"); count++;}  else if((document.getelementsbyname("seller")[0].value) == "")     {alert("who seller?"); count++;} else if(isnan(document.getelementsbyname("topay")[0].value))     {alert("to pay must number"); count++;} else if(isnan(document.getelementsbyname("people")[0].value))     {alert("people must number"); count++;} else if(isnan(document.getelementsbyname("deposit")[0].value))     {alert("deposit must number"); count++;} else if(isnan(document.getelementsbyname("amount")[0].value))     {alert("amount must number"); count++;} return (count==0); } </script> 

the 1 i'm not able solve is:

else if( (((document.getelementsbyname("deposit")[0].value) + (document.getelementsbyname("topay")[0].value)) < "40)")     {alert("the minimum price of product 40"); count++;} 

i want check if (deposit + topay) < 40. noticed code checking if (deposit < 40) , don't understand why.

can please me?

the '+' operator acts concatenation operator in conditional statement(or performs concatenation).

hence make perform addition operation use,

else if( ((parseint(document.getelementsbyname("deposit")[0].value) + parseint(document.getelementsbyname("topay")[0].value)) < 40))     {alert("the minimum price of product 40"); count++;} 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -