2

I have a user registration form in PHP .I put captcha image check in the page.I used it like this

<img src="captcha.php" alt="Enter this text in the adjacent text box" id="imgCaptcha" />

and in my javascript i will validate this with the same number which is generated in the image (from captcha.php page) . That number was set in a session variable too. Now i want to reload the image to another image from my javascript , if the validattion fails .Is there any way to do so ?

In my captcha.php page,I am creating a Number randomly and then creating an image using imagejpeg. I set this number (in the image) to as session varible also

Please guide me to solve this

Thanks in advance

1
  • 2
    you probably want to change the Alt attribute to Title. Alt text will be displayed in case the image can't be loaded, or the user specifically disabled image loading. In that case, the user will not be able to read the captcha image and enter anything in the adjacent text box. Or do you actually want the user to enter "Enter this text in the adjacent text box" into the text box? (I know you don't, but that's how confusing it could get if you use Alt instead of Title) Commented May 16, 2009 at 9:01

1 Answer 1

5

You need to inject captcha.php into the page using ajax. There are several ways to do this:

  • javascript using XHR but this can be a pain. Here is an example.
  • jQuery provides a simple way to do this, for example:

    $('#someButton').click(function() { $('#someDiv').load('captcha.php'); });

  • prototype.js is a bit more verbose, but does the job. Example.

I would suggest using jQuery, there are great examples in the docs.

If your registration page returns on a validation error, you do not need to use javascript for the captcha to get reloaded, that should happen automatically.

Sign up to request clarification or add additional context in comments.

1 Comment

awesome answer. +3 (oh, but only one counts ;))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.