I want to calculate sum of two input value by jquery. I am try with this code but in not work correctly.
My code is:
<script type="text/javascript"> var first_number=$('#first_number').val(); var second_number=$('#second_number').val(); var sum_val=first_number+second_number; alert(sum_val); </script>
If my input values are 10 and 15, it show me 1015 but I want 25.
If you have any suggestion please share.
You need to use parseInt() when you get value from input box using jquery.
Use this code to calculate sum of two input value by jquery.
Example code:
<script type="text/javascript"> var i=parseInt(1); var num_val=parseInt($('#adults_number').val()); var inc_val=num_val+i; alert(inc_val); </script>
Question and answer is powered by AnsPress.io