Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!