JQuery adding variables

I used the following code to add three variables, but instead of adding these variables, it combines these variables.

var registration_fee = $('input[type="radio"][name="registration_fee"]:checked').val(); var material_fee = $('input[type="radio"][name="material_fee"]:checked').val(); var tuition_fee = $('input[type="radio"][name="tuition_fee"]:checked').val(); // alert(tuition_fee) var total_fee = registration_fee + material_fee + tuition_fee; $('#total_fee').html(total_fee); 
+6
source share
5 answers

Pass them to numbers using parseInt or parseFloat :

 var total_fee = parseInt(registration_fee) + parseInt(material_fee) + parseInt(tuition_fee); 
+13
source

Try:

 var total_fee = parseInt(registration_fee, 10) + parseInt(material_fee, 10) + parseInt(tuition_fee, 10);
var total_fee = parseInt(registration_fee, 10) + parseInt(material_fee, 10) + parseInt(tuition_fee, 10); 

Or parseFloat, whichever suits

+2
source

Try

Pass them to numbers using Number

tal_fee = Number (registration_fee) + Number (material_fee) + Number (tuition_fee);

+2
source

Use parseInt to convert a string to int or parseFloat for float.

+1
source

Try using parseInt(price) + parseInt(ticket_buyer_fee) for the variables that it uses.

0
source

Source: https://habr.com/ru/post/906997/


All Articles