In Javascript - How to make the input accept comma and dot in this my scribe. Returning the values of the installments

Asked

Viewed 371 times

2

HTML

<body>
    <form name="frm" method="post">
        valor: <input type="text" name="valor" id="valor" onchange="alteraPonto()">
        <input type="button" value="calcular" onclick="calcularParcelas('valor')">
        <p id="resultado"></p>
    </form>
</body>

JS:

function calcularParcelas(campo) {
    var valor = document.getElementById(campo).value

    var entrada = Math.floor(valor / 3) + valor % 3; // Math.floor traz o resultado inteiro da divisão somado ao resto(% = mod) da divisão
    var parcelas = Math.floor(valor / 3); // O próprio javascript já cria as parcelas na chamada parcelas        
    var solucao = "<hr><p>Valor da Compra:   " + valor + "</p>" +
        " <p>Valor Entrada:   " + entrada + "</p>" +
        " <p>Parcela 01:   " + parcelas + "</p>" +
        " <p>Parcela 02: " + parcelas + "</p>";

    document.getElementById("resultado").innerHTML = solucao;
}

1 answer

1


Do the following that should work:

var temp = document.getElementById(campo).value;
var valor = temp.replace(",", ".");
  • Thanks for the interest. It worked!!! Thanks!!!

  • Not at all, friend! We are here to strengthen the community in Portuguese, a hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.