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

197
Visualizações
how to call an alert after an option is clicked

I am trying to make a username, ID and password linking form but i need to make sure that the program recognises that a username has been selected. This is what I have done;

var usernameBox = document.getElementsByName("uop");
    usernameBox.onclick = function(){
        if (usernameBox.options[usernameBox.selectedIndex].value == false){
        alert("Please choose your username");
    }
    }

this does not work for me and I am a beginner to javascript so I'm not very familiar with a lot of the concepts but that's what learning is for right.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You could update a variable everytime the 'select' element is changed, then show the alert. You can use the username variable wherever you would like. Here is how you could do this...

var usernameBox = document.getElementById("uop");
let username = usernameBox.value;

usernameBox.onchange = (e) => {
  username = e.target.value;
  alert(username);
}
about 4 years ago · Juan Pablo Isaza Relatório

0

You could add the onchange attribute in the HTML itself, which calls a function in the JavaScript. Heres a example

<input type="text" onchange="inputOnChange()" id="input-username"/>
<script> 
function inputOnChange() {
   let usernameinput = document.getElementById("input-username");
   let username = usernameinput.value;
   // do whatever u want with the username now
   console.log(username);
}
</script>

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