Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
654 views
in Technique[技术] by (71.8m points)

html - Input fields are retaining their values after a page refresh, how to prevent that?

<table id="post">
    <tr>
        <td style="font-size: 20px;">Post Your comment</td>
    </tr>
    <tr>
        <td>Name:</td>
        <td><input type="text" id="username" name="username"></td>
    </tr>
    <tr><form id="postform" action="" method="post" name="form">
        <td>Type your message here:</td>
        <td><textarea name="text" id="text" rows="5" cols="40"></textarea></td>
    <tr>
        <td><input type="hidden" id="pageid" name="pageid" value="20"></td>
    </tr>
    <tr>
        <td><input id="submit" type="submit" value="Post Comment"  name="submit" style="width:auto;"/></td>
    </tr>
    </form>
    </tr>
</table>

The page is retaining value in textbox and textarea after refresh.Can anyone suggest me the way to overcome it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Those values are just auto-filled by the client side (the webbrowser) based on the client history. You need to add autocomplete="off" to the form or the individual input fields for which you'd like to turn it off.

<form autocomplete="off">
    ...
</form>

or

<form>
    <input autocomplete="off" />
    <input />
    <input autocomplete="off" />
    ...
</form>

No need for nasty JS hacks which may not work on all environments.

See also:


Unrelated to the concrete problem, your HTML structure is far from valid. I'd suggest to pass your page through http://validator.w3.org and fix the errors/warnings accordingly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...