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

191
Views
How to make a click event behave like a propmt?

I'm trying to get an HTML element's id and process it with a function called process input whenever that element is clicked instead of having the user enter the id themselves.

// this function doesn't execute until I get the user to define the user input variable, which works fine. 
function getUserInputUsingPrompt() {
    let userInput = prompt('Please, enter either rock, paper or scissors');
    
    processInput(userInput); //Works :)
}
// but in this function, the code doesn't stop excuting until a click event is fired :(
function getUserInputUsingClickEvent() {
    let userInput = ''
    let buttons = document.querySelectorAll('img');
    buttons.forEach(button => {
        button.addEventListener('click', e => userInput = e.target.id)
    })
    processInput(userInput); // Doesn't work :(
}

function processInput(input) {
    //do some work with input.
}


I am trying to make the function with the click event stop executing until I get a click event which will define the userInput variable.

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!