0

I have a problem with addition two numbers.

 var dobanda = $('.dobanda').val();
 var val1 = $('.amount1').val();
 $('.total_suma').val(dobanda + val1);

dobanda = 100
val1 = 30

show: 10030

3 Answers3

1

Try this:

Please node you may need to use parseInt or parseFloat depending on your value.

var dobanda = parseInt($('.dobanda').val());
var val1 = parseInt($('.amount1').val());
$('.total_suma').val(dobanda + val1);
Ish
  • 2,085
  • 3
  • 21
  • 38
0

Use parseInt or parseFloat to convert a variable into integer or float.

http://www.w3schools.com/jsref/jsref_parsefloat.asp

http://www.w3schools.com/jsref/jsref_parseint.asp

This is how you have to do.

 var dobanda =parseFloat($('.dobanda').val());
 var val1 = parseFloat($('.amount1').val());
 $('.total_suma').val(dobanda + val1);

parseInt will neglect the decimal points and will give you only integer value.Use parseFloat if you have decimal points(eg. 10.59)

Example

var number1 = parseInt(10.59);
var number2 = parseFloat(10.59);

Result:

number1=10;
number2=10.59
Jayababu
  • 1,641
  • 1
  • 14
  • 30
0

Convert the string to integer using parseInt.

 var dobanda = $('.dobanda').val();
 var val1 = $('.amount1').val();
 $('.total_suma').val(dobanda + val1);