javascript - How to add input values -
i have 4 text boxes namely customer_phy_tot
, customer_che_tot
, customer_bio_tot
. i'm trying add , display 3 input boxes values 4th input, customer_pcb_tot
.
customer_bio_obt.blur(function(){ var customer_pcb_tot = isnan(parseint($("#customer_phy_tot").val() + $("#customer_che_tot").val() + $("#customer_bio_tot").val())) ? 0 :( $("#customer_phy_tot").val() + $("#customer_che_tot").val() + $("#customer_bio_tot").val()) $("#customer_pcb_tot").val(customer_pcb_tot); });
the problem instead of adding code treating string. suppose have values 10
, 15
, 5
respectively. it's supposed display 30
in 4th box in case showing 10155
.
any appreciated.
you're using parseint()
already, need use on string values returned each individual val()
call. note use of ternary expression redundant. try this:
customer_bio_obt.blur(function() { var customer_pcb_tot = parseint($("#customer_phy_tot").val(), 10) + parseint($("#customer_che_tot").val(), 10) + parseint($("#customer_bio_tot").val(), 10); $("#customer_pcb_tot").val(customer_pcb_tot || 0); });
Comments
Post a Comment