Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

270
Visualizações
Obtaining all outputs from the inputs using HTML and JS
    var br = document.createElement("br");
    function productCheck() {

        var form = document.createElement("form");

        var price = document.createElement("input");
        price.setAttribute("type", "number");
        price.setAttribute("id", "number1");
        price.setAttribute("placeholder", "Product Price");
        price.onchange = handleChange;

        var qty = document.createElement("input");
        qty.setAttribute("type", "number");
        qty.setAttribute("id", "number2");
        qty.setAttribute("placeholder", "quantity");
        qty.onchange = handleChange;

        var discount = document.createElement("input");
        discount.setAttribute("type", "number");
        discount.setAttribute("id", "number3");
        discount.setAttribute("placeholder", "discount");
        discount.onchange = handleChange;

        var div = document.createElement("div");
        div.setAttribute("id", "total");
        form.appendChild(br.cloneNode());
        div.onchange = handleChange;

        form.appendChild(price);
        // Inserting a line break
        form.appendChild(br.cloneNode());
        ...

        form.appendChild(qty);
        ...

        form.appendChild(discount);
        ...

        form.appendChild(div);
       ...

        document.getElementsByTagName("body")[0]
            .appendChild(form);
    }

    function handleChange() {
        var p = document.getElementById("number1").value;
        var q = document.getElementById("number2").value;
        var d = document.getElementById("number3").value;

        var total = parseFloat(p) * parseInt(q);
        var discount_applied = parseFloat(total * d / 100);
        var eff_price = parseFloat(total) - parseFloat(discount_applied);

        if (!isNaN(eff_price))
            return " ";

        if (p > 0 && q > 0){
            var eff = document.querySelector("#total");
            eff.innerHTML = eff_price.toFixed(2);
       }
    }
Add more fields

Created a form with multiple inputs. The issue lies in the output. I am only getting 1 output. After adding multiple inputs, I am getting only output in the first occurence. How do I resolve it for each occurence? I want the solution only using JS and HTML. No jquery is allowed in this.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

var elms = document.forms["form_name"].getElementsByTagName("input");
for (let index = 0; index < elms.length; index++) {
    const element = elms[index];
    console.log(element.value);
 }

You also need to give your form the "name" attribut (in my example i called it "form_name")

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda