JQuery Ajax displays the check mark and error number to verify that the entered verification code is correct. jqueryajax

Source: Internet
Author: User

JQuery Ajax displays the check mark and error number to verify that the entered verification code is correct. jqueryajax

If you don't talk much about it, paste the Code directly. The specific code is as follows:

<script src="js/j.js"></script><script>$(document).ready(function(e) { $('#yes').hide(); $('#no').hide();  $('input[name=gcode]').keyup(function(){   if($(this).val().length==4){  $.post('gbook.php',{cc:$('input[name=gcode]').val()},function(msg){      if(msg=='yes'){    $('#no').hide();    $('#yes').show();   }else{    $('#yes').hide();    $("#no").show();   }  });  } });});</script>

First introduce jquery

.sl-error-verifycode { background-image: url("images/icons.png"); background-position: -26px 0; background-repeat: no-repeat; display: block; font-size: 18px; height: 23px; line-height: 20px; margin-left: 180px; margin-top: -25px; position: relative; text-align: center; width: 20px; z-index: 2;}.sl-correct-verifycode { background-image: url("images/icons.png"); background-position: -50px 0; background-repeat: no-repeat; display: block; font-size: 18px; height: 23px; line-height: 20px; margin-left: 180px; margin-top: -25px; position: relative; text-align: center; width: 20px; z-index: 2;}

Html code of the Verification Code

<Tr> <td height = "40" align = "right"> Verification Code: </td> <td height = "40"> <span class = "addred"> * </span> </td> <td height = "40"> <input type = "text" name = "gcode" id = "textfield7" class = "txtlist"> <span id = "yes" class = "sl-correct-verifycode"> </span> <span id = "no" class = "sl-error-verifycode"> </span>  </td> </tr>

Gbook. php

<?phpsession_start();if(isset($_POST['cc'])){ $cc = strtolower($_POST['cc']); $ss = strtolower($_SESSION['code']); if($cc==$ss){   echo "yes"; }else{   echo "no";  }}

Note that images must be imported

The preceding section describes how to use jQuery Ajax to display the check mark and error number to verify whether the entered verification code is correct. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.