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

200
Views
Trying To Match Two Fields Before Form Submit With Javascript

I am trying to match two fields with the result in my javascript before the form gets submitted but not working.

I don't want the form to get submitted if the results don't match.

Please what is the solution? Thanks.

Code Below;

function Check(){
    var done=0;
    var check=document.check.phone.value;
    var check=document.check.pcode.value;
    
    if (phone=="08023" && pcode=="12345") {
 alert ("Result Match!");
              
                done=1;
return fasle;

    }
    if (done==0) {
   
alert("Result Don't Match!");

}
}
<form action=" " method="post">
 
<input name="phone" maxlength="11"  type='tel' id="phone" placeholder="0000-000-0000" required="" />
          <br/><br/>
             
<input name="pcode" maxlength="11"  type='tel' id="pcode" placeholder="0000-000-0000" required="" />

<br/><br/>

 <button class="button" onClick="javascript:Check()"  name="Submit" type="submit" value="Login"><span>Log In </span></button> 

</form>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have several mistakes in your code, I have cleaned it up a bit for you.

        function Check() {
            var done = 0;
            var phone = document.check.phone.value;
            var pcode = document.check.pcode.value;

            if (phone=="08023" && pcode=="12345") {
                alert("Result Match!");
                done = 1;
            } else {
                alert("Result Don't Match!");
            }
        }
    <form name="check" action=" " method="post">
        <input name="phone" maxlength="11" type='tel' id="phone" placeholder="0000-000-0000" required="" />
        <br /><br />
        <input name="pcode" maxlength="11" type='tel' id="pcode" placeholder="0000-000-0000" required="" />
        <br /><br />
        <button class="button" onClick="javascript:Check()" name="Submit" type="submit" value="Login">
            <span>LogIn</span></button>
    </form>

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