Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to add two textbox value (10,20) but it concatenate the data(1020) rather than add data(30). See code below

function add() {
           var a = document.getElementById("TextBox1").value;
           var b = document.getElementById("TextBox2").value;
           var c = (a+b);
           document.getElementById("TextBox3").value = c;

       }

<input id="Button1" type="button" value="+" onclick="add()" /></td>


So guys help me how can i add data
Posted

Hi,

use like this,
JavaScript
var c = (parseInt(a)+parseInt(b));

Thanks,
Raja S
 
Share this answer
 
v2
Comments
Mas11 6-Jul-12 6:48am    
Thanks a lot bro.. It worked
here you are adding two vars that will concatenate two vars.
addintion is apply to Integer values so you need to convert your a and b into int and then store it into var c then display c.

best of luck.
 
Share this answer
 
Comments
Mas11 6-Jul-12 7:10am    
Thanks !! nice answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900