views:

44

answers:

2

Do you know when you use in a form the password field, like this:

<input type="password" name="pass">

And you do a GET or POST submit to the same page who have the form and if the user hit back in the browser the password field gets blank. Well thats good, but i need to get blank another form field when the user hit back. Thats because i asking for a captcha and the text field who hold the information entered by the user ramain fill when he hit back, but the captcha image change, and if i dont blank the field the user (sometimes) dont get that he needs to re-enter the captcha.

Thanks!

+1  A: 

Javascript
window.onload(function()
{
document.getElementById("CaptchaTextBox").value = '';
});

html
<input type="text" id="CaptchaTextBox" name="Captcha" />

Javascript erases the value of the textbox when the page is loaded

Kant
This won't suffice, as `onload` is not triggered when returning to a page using the back button
Marcel Korpel
thats right, what do you suggest?
DomingoSL
Well then in that case a new captcha image would not be generated either because this requires communicatino back with the server.
Kant
So what I'm trying to say is that the same captcha image will show so the textbox should contain the correct value.
Kant
+1  A: 

Try randomizing input name on each refresh, like:

<input type="text" id="CaptchaTextBox" name="captcha[612361]" />

Browser will notice that input field is different and will clear the value

Edit:

I have better solution: as user typed captcha once, just let him go without typing it second time. Now you know that this user is fairly non-machine so why give him so much to do ;)

shfx
That won't be retrieved on pressing the back button
Marcel Korpel
Maybe this will help ;)
shfx
Great, this is *way* easier to implement and much more user-friendly!
Marcel Korpel