samedi 29 avril 2017

Calculate the total of form immediately without having to check a checkbox

I have an HTML, JavaScript form, which calculates a price based upon choices made in the form. The problem is that the total price will only be calculated after one checkbox has been clicked. I want it to calculate the price immediately without having to check a checkbox first. Below is a snippet of the JavaScript code:

function totalIt() {
  var input = document.getElementsByName("product");
  var total = 0;
  for (var i = 0; i < input.length; i++) {
    if (input[i].checked) {
        total += parseFloat(input[i].value); // this function should run immediately
    }
  }
  document.getElementById("total").value = "€" + total.toFixed(2);
}

The full form can be found here.

How can this be done?




Aucun commentaire:

Enregistrer un commentaire