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

193
Visualizações
JS function onclick is not working. It is not calling validations

Below is function and it is not working. Maybe some small bug in the code which I am unable to identify.

<!DOCTYPE html>
<script>
function check(){
  firstname=document.getelementById("firstname").value;
  lastname=document.getelementById("lastname").value;
  if(lastname==""){
    alert('please enter lastname');
  }
}
</script>

<form action="" method="post" onSubmit="check();">
            <input type="text" id="firstname" name="firstname" ><br>
            <input type="text" id="lastname" name="lastname" ><br>
            <input type="submit"  value="submit">
</form>
</body>
</html>
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The bug in the code: case sensitive getelEmentById. Please below code and test it

function check(){
  firstname=document.getElementById("firstname").value;
  lastname=document.getElementById("lastname").value;
  if(lastname==""){
    alert('please enter lastname');
  }
}
about 4 years ago · Santiago Trujillo Relatório

0

GetElementById, element with a capital E
JavaScript is case sensive. TIP: use developer options in your browser. They usualy give an error message.

<!DOCTYPE html>
<script>
function check(){
  firstname=document.getElementById("firstname").value;
  lastname=document.getElementById("lastname").value;
  if(lastname==""){
    alert('please enter lastname');
  }
}
</script>

<form action="" method="post" onSubmit="check();">
            <input type="text" id="firstname" name="firstname" ><br>
            <input type="text" id="lastname" name="lastname" ><br>
            <input type="submit"  value="submit">
</form>
</body>
</html>

about 4 years ago · Santiago Trujillo 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