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

196
Vistas
How can I get multiple elements from an array?
const studentName = [];

function AddNewMember(){
    for(var i=0; i<4 ; i++){
        var num1 = document.getElementById("vorodi").value;
        studentName.push(num1);
    }
}

I have an input from which I want to receive five names. You can't do this with this code. What is the solution to this problem?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

you can use this solution

let num1 = document.getElementById("vorodi");
function AddNewMember(){
        let name = num1.value;
        studentName.push(name);
        num1.value = "";
        console.log(studentName);
    }

about 4 years ago · Juan Pablo Isaza Denunciar

0

As I understand you want to take value of multiple inputs in (your case it is 4)

You can try below one "vorod"+i concat value of i with static text

const studentName = [];

function AddNewMember(){
alert("called")
    for(var i=0; i<4 ; i++){
        var num1 = document.getElementById("vorod"+i).value;
        studentName.push(num1);
    }
    console.log(studentName)
}
  <input type="text" id="vorod0"><br><br>
  <input type="text" id="vorod1"><br><br>
  <input type="text" id="vorod2"><br><br>
  <input type="text" id="vorod3"><br><br>
  <input type="button" value="Add Member" onclick="AddNewMember()">

about 4 years ago · Juan Pablo Isaza Denunciar

0

I don't know exactly what you are trying to do but if you want to get mutiple elements from your document(assuming you are working with a html page) you can use the getElementsByClassName() or getElementsByTagName() functions but you have to put the tag or class in your html element.

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