0
I have this site and I need to implement a sum with input[type=radio].
That’s the page where I do the sums
This is the Javascript code that makes the sums.
<script>
        function formatCurrency(num) { // função original - sem modificação
          num = num.toString().replace(/\$|\,/g, '');
          if (isNaN(num)) num = "0";
          cents = Math.floor((num * 100 + 0.5) % 100);
          num = Math.floor((num * 100 + 0.5) / 100).toString();
          if (cents < 10) cents = "0" + cents;
          for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
            num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
          return ("" + num + "." + cents);
        }
        var form = document.forms[0];
        var inputs = form.querySelectorAll('input[type=radio]');
        // iterar todos os inputs
        for (var i = 0; i < inputs.length; i++) {
          // vincular função ao evento "change"
          inputs[i].addEventListener('change', function() {
            var soma = 0;
            for (var j = 0; j < inputs.length; j++) {
              if (inputs[j].checked) {
                // interpreta como float, usando parseFloat ao invés de eval
                soma += parseFloat(inputs[j].value);
              }
            }
            form.hiddentotal.value = soma; // atribui valor ao campo oculto
            form.total.value = formatCurrency(soma) // exibe valor formatado
          }, false);
        }
                        </script>
But nothing appears... it does not generate the result...
In this other link it works perfectly... should it be something in the code?
That ain’t java, that’s right javascript. They are very different languages.
– user28595
@Sorry Moltres :D
– Betinho Silva