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

192
Vistas
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
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