How to reset text input value on page reload?

Firefox (and possibly other browsers) want to save any text entered by the user into text input, even after a reboot. Just including the default text (which I want the input to return to) in html did not work:

<input tyep='text' value='default text' />

And not trying to use JS

window.onload = function() {document.getElementById("mytextinput").value = 'default text'}
+4
source share
4 answers

You can use plain old HTML :)

Set autocomplete='off'in attribute

<input type='text' value='default text' autocomplete='off' />

This works in most modern browsers.

+16
source

Technically, you do not need to run the onload function to clear it - you can just put javascript directly on the page. For instance:

document.getElementById("mytextinput").value = ''

or using jQuery

$("mytextinput").val('');

, dom, , javascript dom. , jQuery ,

$(document).ready(function() {
   $("mytextinput").val('');
});
+3

:

<input type='text' id='mytextinput' value='default text' />
<script>
    document.getElementById("mytextinput").value = 'default text';
</script>

. onload , , , .

script -, , .., .

, , "" .

0

I think you should do server-side encoding when reloading the page. Page reloading is usually an idea like postback. The page reloads from the server. If you are using asp.net, add the default text in the page_load method. :)

0
source

All Articles