DomingoSL
DomingoSL

Reputation: 15504

Clearing a form field when page goes back (html / javascript)

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!

Upvotes: 2

Views: 1638

Answers (2)

shfx
shfx

Reputation: 1289

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 ;)

Upvotes: 1

Saturn K
Saturn K

Reputation: 2785

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

Upvotes: 1

Related Questions