Skip navigation

Currently Being Moderated

Clearing the values of form fields when a visitor browses back to a previously submitted form

Mar 26, 2012 9:24 PM

Implement the following script to make your site more secure. For example, add this code to ensure that a visitor's entries into a web form are not 'viewable' by navigating 'back' to the page after the form's submission. Place the following code on the page with the web form.

 

 

<script type="text/javascript">
var ele = document.getElementsByTagName('input');
var len = ele.length;
for(var i=0;i<len;i++){
    if(ele[i].type == 'text')
          ele[i].value='';
}    
</script>


Another option is to add the following to your web form: autocomplete = "off"

<form name="form1" id="form1" method="post" autocomplete="off"  action="">

 

Jquery Version

You can add the following into your script or page to clear form fields:

$(this).closest('form').find("input[type=text], textarea").val("");


 
Comments (0)