How to reset all data in a form if the user returns to the page?

2

I have a form that, after being submitted, displays the result on a second page, type:

<form method="post" id="form" action="form.php">
<input name='nome' id='nome'>
<input type='submit' value='Enviar'>
</form>

And no form.php something like:

$nome = $_POST['nome'];
echo "O nome é $nome";

This question is answered how to reset the data when the request is processed on the same page, but I need the data that has been filled out to be completely zeroed if the user returns the page through the browser button or using the keyboard. I tried:

<script>
    $('#myForm')[0].reset();
</script>

But it did not work. What I need is that if the user returns to the page, the field is no longer filled. The form has several types of fields (select, input, checkbox, radio), and I need to reset all.

I read several issues in SOen, but due to the language barrier I was even in doubt about this is even possible.

Is it possible? How?

    
asked by anonymous 04.03.2017 / 12:40

2 answers

2

You're on the right track, but when the browser comes back, it does not reload the scripts, so a means of firing it is needed.

Using the onpageshow event, it should be possible to trigger such an event. I have not tested but it should work:

$(window).bind("pageshow", function() {
   $('#myForm')[0].reset();
})
    
09.03.2017 / 15:12
5

Another option is to use autocomplete to off , for example:

<input type="text" autocomplete="off" value="" name="nome_do_input">

Using autocomplete="on" , default:

Usingautocomplete="off" :

    
13.03.2017 / 21:17