6

I have an input field on a webpage that contains a credit-card number. What is the best way of preventing the browser from caching this value?

Any solution needs to work on a large selection of browsers.

Simon Johnson
  • 7,802
  • 5
  • 37
  • 49
  • 1
    If by "caching" you mean for field autocompletion, see http://stackoverflow.com/questions/582244/is-there-a-w3c-valid-way-to-disable-autocomplete-in-a-html-form. – womp Apr 26 '10 at 16:44

2 Answers2

8

Put attribute autocomplete="off" to your html form. E.g.

<form name="form1" id="form1" method="post" autocomplete="off"
  action="http://www.example.com/form.cgi">
[...]
</form>

See this page.

Juha Syrjälä
  • 33,425
  • 31
  • 131
  • 183
4
<asp:TextBox Runat="server" ID="Textbox1" autocomplete="off"></asp:TextBox>
Kobi
  • 135,331
  • 41
  • 252
  • 292
  • I can't believe I've not seen that before. I must have been living a bubble! Thanks. – Simon Johnson Apr 26 '10 at 16:46
  • The TextBox has an `AutoCompleteType`, but it doesn't support `off`. Also, womp's comment adds useful details on the subject. If you need this for security, maybe you need more... – Kobi Apr 26 '10 at 16:49
  • For further information on the `AutoCompleteType` enumeration, see [here](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.autocompletetype.aspx). It might not support, `Off` but it supports `Disabled`. – Simon Johnson Apr 26 '10 at 17:06
  • @Simon - I did check before I posted, and `Disables` didn't generate `autocomplete` for me. Odd. Possibly because I'm using Firefox/ – Kobi Apr 26 '10 at 19:42
  • I've confirmed this myself. On that basis, I'm going to move the accepted answer to Juha. Thanks for the help! – Simon Johnson Apr 27 '10 at 09:00