For example i want addition value two input 20 & 10 and done output in alert but i get in output value 2010 If the i should have this output 30, how is fix it?
Demo: http://jsfiddle.net/SHjZM/
<input type"text" name="ok1" value="20">
<input type"text" name="ok2" value="10">
$('button').live('click', function(){
var val_1 = $('input[name="ok1"]').val();
var val_2 = $('input[name="ok2"]').val();
var Sum = val_1 + val_2;
alert(Sum) // in the here output is "2010" i want output "30" as: "20+10=30"
})
you need to convert variable to integers before addition
Update:
If no radix argument is provided or if it is assigned a value of 0, the function tries to determine the base. If the string starts with a 1-9, it will be parsed as base 10. If the string starts with 0x or 0X it will be parsed as a hexidecimal number. If the string starts with a 0 it will be parsed as an octal number. (Note that just because a number starts with a zero, it does not mean that it is really octal.)
http://devguru.com/Technologies/ecmascript/quickref/parseint.html