Click here to Skip to main content
Click here to Skip to main content

Simple JavaScript Captcha Code

, 30 Jul 2010
Rate this:
Please Sign up or sign in to vote.
Simple JavaScript Captcha Code
Steps:->
 
1. In the .aspx page.I write the javascript code
 
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
     <script language="javascript">
         var a = 49, b = 65;
         var c = 100;
         var d = 70;
  function show()
  {
      if (a == 57) {
          a = 49;
      }
      var main = document.getElementById('txt1');
      var a1 = String.fromCharCode(a);
      var b1 = String.fromCharCode(b);
      var c1 = String.fromCharCode(c);
      var d1 = String.fromCharCode(d);
      main.value = a1 + b1 + c1 + d1;
a = a + 1;
b = b + 1;
c = c + 1;
d = d + 1;
  }
  </script>
    <style type="text/css">
        #form1
        {
            height: 95px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input type="text" id="txt1" runat="server"
       style="border-style: none; border-color: inherit; border-width: medium; background-color:black; color:red; font-family: 'Curlz MT'; font-size: x-large; font-weight: bold; font-variant: normal; letter-spacing: 10pt; width: 120px; background-image: url('glitter_background_b4.gif');"
            value="5AbD" />
  <input type="button" onclick="show()" value="Change"  />
        </div>
    <asp:TextBox ID="txtverification" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button ID="Button1" runat="server" Text="Verification"
        onclick="Button1_Click" />
    &nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Label ID="lblmsg" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
    </form>
</body>
</html>
 

2. In the .cs page:->
 
protected void Button1_Click(object sender, EventArgs e)
   {
       if (txtverification.Text == txt1.Value)
       {
           lblmsg.Text = "Successfull";
       }
       else
       {
           lblmsg.Text = "Failure";
       }
   }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

mahakgupta

India India
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 30 Jul 2010
Article Copyright 2010 by mahakgupta
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid