how to stop storing field data in forms using javascript...
Moderator: General Moderators
- 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...
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
Also, at the first point, the browser should not cache / save the data inputted to the form
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
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 ?
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.
Hope that will work for you.
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>- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Wow, that's really simple! I did some research on that attribute and from what I can tell this is how it is used:
Note: This attribute is not a valid HTML attribute.
Code: Select all
<form action="form.php" method="post" autocomplete="off">
</form>- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
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.
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.
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
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.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.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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.
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.