Page 1 of 1
how to stop storing field data in forms using javascript...
Posted: Wed May 24, 2006 4:03 am
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
Posted: Wed May 24, 2006 4:25 am
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 ?
Posted: Wed May 24, 2006 4:33 am
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.
Posted: Wed May 24, 2006 6:45 am
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"

Posted: Wed May 24, 2006 6:55 am
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.
Posted: Wed May 24, 2006 7:45 am
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.
Posted: Wed May 24, 2006 8:58 am
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.
Posted: Wed May 24, 2006 9:54 am
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.
Posted: Wed May 24, 2006 12:46 pm
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.
Posted: Wed May 24, 2006 1:54 pm
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.