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

270
Views
While Using getElementById, How can I access a specific index in a array and reassign digits, after submitting numbers from a input felid with html

I'd successfully obtain arbitrary numbers from an input field while utilizing a callback function on the HTML side which eventually passed the original numbers down to an Array constructor. Inside my function, I've reassigned the document.getElementById("text1").value that called the original numbers to a variable and a number representing a 0 index that leads to the first index within an Array constructor. The issue is, after pushing original numbers to arrayAbove (an empty array) I was not able to select the original numbers by index to reuse them later in a conditional statement. I've used a for loop to iterate the arrayAbove array and had no luck with this approach. I'm presuming the issue lies within the Array() constructor, the format inside the inspection tool displays an empty array with sequential indexes underneath the empty array, nothing I've observed before.

Any reason why? Hope this all makes sense.

index.html

</div>  
  <input placeholder="Enter Limit" type="text" id="text1"></input>
  <input   type="button" id="stopLoss" value="Add" onclick="add_element_to_array()"><input>
  <input type="button" id="button2" value="Display" onclick="display_array();"> 
  </input>
  <div id="Result"></div> 
</div>

JS:

bot.Js
var x = 0
var stopLoss = Array();
let arrayAbove = [] 

var arrName = new Array()

async function add_element_to_array(){

    stopLoss[x] = document.getElementById("text1").value;
    arrayAbove.push(parseFloat(stopLoss[x].replace(/[a-z]/i, '')))
    alert("Element:" + stopLoss[x] + "Added at index" + x);
    x++;
    document.getElementById("stopLoss").value = "";


    // console.log(tokenAmount)
}
function display_array() {
    var e = "<hr/>";

    for (var y = 0; y < stopLoss.length; y++) {
        e += "Element" + y + " = " + stopLoss[y] + "<br/>"

    }
    document.getElementById("Result").innerHTML = e;
}
console.log(arrayAbove)
console.log(arrName)

about 4 years ago · Juan Pablo Isaza
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!