Captcha IMG/Numbers Combination

Go To StackoverFlow.com

0

I'm trying to create a Captcha in Javascript but I ran into issues. I want the CAPTCHA to display at random, one of the declared images and then validate users input against the text on the images. So far, I have the Code below and it doesn't show anything.

<script type="text/javascript"> 
    var "<img src="images/ci0.jpg" />" = 56777;
    var "<img src="images/ci1.jpg" />" = 67646;      
    var "<img src="images/ici2.jpg" />" = 77666;           
 var code = ci0, ci1, ci2;
 document.getElementById("txtCaptcha").value = code;
  document.getElementById("txtCaptchaDiv").innerHTML = code;
  </script>

HTML

  <div id="left">

         <label for="code">Enter code next  <span id="txtCaptchaDiv" style="color:#F00"></span><br />
<!-- this is where the script will place the generated code -->
          <input type="hidden" id="txtCaptcha" /></label>

          </div><!-- End Left -->
        <div id="righty">
        <span id="spryconfirm1">
        <label>
          <input type="text" name="checker" id="checker" />
        </label>
        <span class="confirmRequiredMsg">You must enter the Code.</span><span class="confirmInvalidMsg">The values don't match.</span></span>

        </div><!-- End righty -->  



       </div>
2012-04-03 21:56
by Dz.slick
Excuse me, in Java? I think you meant JavaScript - Alexander 2012-04-03 22:00
var "<img src="images/ci0.jpg" />" = 56777; You have mismatched quotes, escape them or change them to simple quotes. Also var code = ci0, ci1, ci2; so var code = ci2;. I assume that ci2 is defined somewhere else - mamadrood 2012-04-03 22:08


0

By the way I see it you should use reCAPTCHA since you still have a long way to go before creating a CAPTCHA validator yourself. This is not only a matter of client-side but also server-side which you are already ignoring.

Get a reCAPTCHA embed code and use it in your HTML.

2012-04-03 22:06
by Alexander