Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

262
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda