Return False not working inside jQuery.ajax

前端 未结 7 1923
再見小時候
再見小時候 2021-02-08 17:38

P.S.: Read \"EDITED on 2019-06-29\":

I have a webform for updating user information, and when he updates his email a verification is performed via

相关标签:
7条回答
  • 2021-02-08 18:21
    <form action="yourpage" method="post" onsubmit="return matchpass();">
      <div>
       <label> Name</label>
       <input type="text" name="name" id="name">
      </div>
      <div>
       <label> Email ID</label>
       <input type="email" name="email" id="email">            
      </div>
      <div>
       <label> Mobile No</label>
       <input type="text" name="mob"  maxlength="10" onkeyup="check_if_exists();" autocomplete="off" id="mob">
      </div>                             
      <div>
       <button type="button" >Send</button>
      </div>
      <span id="err"></span>
      <div>
       <label> OTP</label>
       <input type="password" name="otp" id="otp"  maxlength="6" placeholder="****">
       <span id="err2"></span>
      </div>    
      <div>
       <input type="reset" value="Reset" class="reset-btn">
       <input type="submit" name="submit" id="submit" value="Submit" >              
      </div>
    </form>
    <input type="hidden"  id="otpcheck"/>
    
    
    
    <script>
    function matchpass()
    {
    
         $.ajax({   
        type:"post",
        url: "yourpage",
        data:{ mobile:mob,otp:otp},
        success:function(data)
        {
           if(data==1)
           {
               document.getElementById("otpcheck").value=1; //important
           }else{
    
               document.getElementById("err2").style.color = "red";
               document.getElementById("err2").innerHTML = "invalid OTP Number ";
             document.getElementById("otpcheck").value=0; //important
           }
    
    
        }
        });
    
        if(document.getElementById("otpcheck").value==0){
            return false;
        }
    
    }
    

    0 讨论(0)
提交回复
热议问题