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

145
Views
How can I call function selected amount of times?

I'm trying to run function getOrderData number of times that user selected in the dropdown, how can I do that?

Jade file:

p
strong Number of pieces:
select(id='numOfPieces')

Javascript file:

function getOrderData() {
      //this just creates the dropdown dynamically so I could get number that user selected by index value
      const dropdown = document.getElementById("numOfPieces"); 
      var options = ["1", "2", "3", "4", "5"]; 
      
      for(var i = 0; i < options.length; i++) {
          var opt = options[i];
          var el = document.createElement("option");
          el.textContent = opt;
          el.value = opt;
          dropdown.appendChild(el);
      }

    //checks selected number
    let times = dropdown.options[dropdown.selectedIndex].value;
}

  $("#yes").click(function () {
    
    getOrderData();
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

function getOrderData() {
  alert('Hallo!!');
}

$("#yes").click(function () {
  let value = $('#numOfPieces').val();
  value = value && value>0 ? parseInt(value) : 1;
  for (let i = 0;  i < value; i++) {
    getOrderData();
  }
});
about 4 years ago · Juan Pablo Isaza Report

0

You can use the times() method from 30 seconds of code. Here is the code from that website, plus an example:

const times = (n, fn, context = undefined) => {
  let i = 0;
  while (fn.call(context, i) !== false && ++i < n) {}
};

times(5, i => console.log(`Called ${ i } times.`));

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!