0
<a href="javascript:void(0);" onclick="document.getElementById("capchaimage").src="captcha.php"><img id="captchaimage" src="http://website.org/captcha.php" border="0" width="70" height="20" alt="Captcha image"></a>

Captcha image successfully loads but it's not possible to reload it with the code above. What am I doing wrong?

Thanks in advance.

Dmitry Ponkin
  • 424
  • 2
  • 10

3 Answers3

1

Your images are cached. Add a random string +(new Date).getTime() to at the query string after the image URL:

document.getElementById("capchaimage").src="captcha.php?"+ (new Date).getTime();
Rob W
  • 341,306
  • 83
  • 791
  • 678
0

You are replacing image src with exactly the same string.

You can try to work around that by using some "fake" arguments:

http://website.org/captcha.php?fake=234342412341

That way the browser will be forced to reload. The argument needs to be different each time of course (random, or just counter)

Gregory Mostizky
  • 7,231
  • 1
  • 26
  • 29
0

Look carefully at your code:

<a href="javascript:void(0);" onclick="document.getElementById("capchaimage").src="captcha.php"><img id="captchaimage" src="http://website.org/captcha.php" border="0" width="70" height="20" alt="Captcha image"></a>
                                      ^                        ^

I'm surprised you are not getting JavaScript syntax errors. My advise is to move code to external functions to avoid the need of complex escaping.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360