Well i was trying to create a simple calculator using HTMl, JS and JQuery , I created two text box for input of numbers but , I am not able to add the given numeric values in the input box , it always concatenate the values . Please Help Me .
when you read the values from your input boxes, you are reading them as strings. unfortuneately for javascript & math, the + symbol means two different things (in math it means add, in js is means concatentate, and, well add sometimes too).
You need to cast your strings as ints ( or floats or whatever) and then add them in javascript. you can do that this way:
var intstr0 = "1";
var intstr1 = "2";
var sum = parseInt(intstr0) + parseInt(intstr1);
Input boxes values' will be strings, and not numbers. To convert that input box to a number, try parseInt() or parseFloat() around the values. Then, you can add them with +.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With