How to refresh Captcha image

Captcha images are very helpful in preventing spammers posting form data into our applications . A captcha image is a image having some distorted text which humans can read but not computer programs. It is a type of test that essures that the response is generated by a person.

In coldfusion captcha images can be easily generated using the tag. This tag is used to perform common image mnipulation operations. To generate captcha image, we just need to provide certain attributes to this tag like action = “captcha”, height = “number of pixel”, text = “text string” width = “number of pixel” and all these are required attribute.

Lets see a example


Enter Text Below:

This simple code will generate the captcha image. Many times it happens that the image generated is not easily readable. So we need to refresh our captcha image or else we enter wrong text and submit the form to regenerate the image and continue the process till we get a wel readable text.
So as a solution to it we can refresh the captcha image using few lines of jQuery code which goes as below :

$(document).ready(function() {
// loads the captchaDiv of refreshCaptcha.cfm page
$("#captchaDiv").load("refreshCaptcha.cfm #captchaDiv"); 

$("#reloadLink").click(function(e) {
$("#captchaDiv").load("refreshCaptcha.cfm #captchaDiv");
e.preventDefault(); 
});
})

And a slight modification in the above code to provide a link to refresh image:

Can’t read? Reload
150 150 Burnignorance | Where Minds Meet And Sparks Fly!