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

192
Views
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 answers
Answer question

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 Report

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 Report
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!