Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda