how to stop storing field data in forms using javascript...

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

how to stop storing field data in forms using javascript...

Post by raghavan20 »

I have to stop the browser from storing field data in forms so that they we won't be accessible / come up when you try to fill the same form next time. Is it possible to achieve this by means of using script, javascript or any other ???

Also, at the first point, the browser should not cache / save the data inputted to the form
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

As I understand the question, the obvious answer would be sessions, with the session variable cleared on form success. I would guess however that I am not understanding the full details of the question... Do you mean you have hidden input fields in the form you need to get rid of or something else ?
User avatar
neogeek
Forum Newbie
Posts: 24
Joined: Sun May 14, 2006 4:24 am

Post by neogeek »

I'm not sure if it is even possible to stop the browser from saving form information. However, the information that the browser places into the input boxes can be easily stripped out using javascript.

Code: Select all

<html>
<head>
<title></title>

<script type="text/javascript">

window.onload = function() {

   var form = document.getElementById('form');
   var tags = form.getElementsByTagName('input');

   for (var i = 0; i < tags.length; i++) {

      if (tags[i].type == 'text') { tags[i].value = ''; }
      else if (tags[i].type == 'checkbox' || tags[i].type == 'radio') { tags[i].checked = ''; }

   }

}

</script>

</head>

<body>

<form action="" method="post" id="form">

<fieldset>

<legend>User Information</legend>

<p><label>Name:</label><br />
<input type="text" name="name" size="40" value="test" /></p>

<p><label>Email:</label><br />
<input type="text" name="email" size="40" value="" /></p>

<p><label>Website:</label><br />
<input type="text" name="website" size="40" value="" /></p>

</fieldset>

</form>


</body>
</html>
Hope that will work for you.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

There's actually an attribute you can use in your markup to disable autocomplete. If you go to the HSBC login page and view source it's in there - I don't remember the exact name for it. Probably "autocomplete=off" :P
User avatar
neogeek
Forum Newbie
Posts: 24
Joined: Sun May 14, 2006 4:24 am

Post by neogeek »

Wow, that's really simple! I did some research on that attribute and from what I can tell this is how it is used:

Code: Select all

<form action="form.php" method="post" autocomplete="off">

</form>
Note: This attribute is not a valid HTML attribute.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

I tried it and I think it stops only from displaying saved form fields but it does not really seem to stop saving form fields.

If you copy the same form and take autocomplete off, then the details you entered earlier would come up.

It means like somebody intelligent enough will copy the form code to another HTML page and take autocomplete off or false and try to fill in fields, they would get the values you typed in earlier when the autocomplete was off or false.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The form saving feature is a browser level setting. We cannot affect it choosing to save data. The only sort-of workaround is making the URL random, but that's not a very good solution.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

If you add a 'disabled' attribute (maybe disabled="on" or disabled="false" to be 100% correct). It will keep the form element visible, but it'll be greyed out a bit & not be posted.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

pickle wrote:If you add a 'disabled' attribute (maybe disabled="on" or disabled="false" to be 100% correct). It will keep the form element visible, but it'll be greyed out a bit & not be posted.
it is not about disabling..let's say they are fields where you enter your credit card details. we do not want anyone to get our credit card details just by looking out from the drop down list when you go to each field in the form.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Put it this way, using the autocomplete=off attribute works in most browsers although not compliant. Evading it invloves some intelligence and some coding. Even then you would need to have it open in the same URL or autocomplete will not work.

Now, your requested method of using JavaScript... It would take a lifetime of hacking away to get past that restriction... last I heard people had not heard how to avoid javascript in web pages. I'm working on it though.
Post Reply