Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How come form.reset() doesn't work after postback on this page?

A student in my class brought this to my attention, and I didn't have an explanation for it-- and I couldn't find one after searching.

After clicking the submit button, the reset button does not work. It's as if the browser prevents reset if the resource has been requested via post request.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <fieldset>
            <legend>User Form</legend>
            <label for="Username"></label>
            <asp:TextBox ID="Username" runat="server"></asp:TextBox>
        </fieldset>
        <asp:Button runat="server" Text="Submit" />
        <input type="button" onclick="window.document.forms[0].reset()" value="reset" />
    </div>
    </form>
</body>
</html>
like image 711
ek_ny Avatar asked Feb 20 '23 00:02

ek_ny


1 Answers

When you click reset then the entries are reset to the default values. Default values are values which were rendered by the server in the first case it was empty string but after post the posted value. (http is stateless protocol) If you try to edit the posted value then click reset you will see that the originally posted value will be restored.

like image 182
Marian Ban Avatar answered Mar 24 '23 01:03

Marian Ban