Here is a basic question (I thought I knew how to do this, but apparently not).

(I am using Firefox 2.0.0.4, in case that is a factor).

I am writing a Javascript page and want one of the text fields to default to a blank when the page is reloaded. Basically, the page accepts a few values via a form, does some calculations in Javascript, and then outputs the results and an Error Code. The page will be run many times, feeding it new inputs each time.
After each execution, if a user clicks the "Reload Page" button, I'd like the Error Code field to be empty. However, presently this field retains the Error Code value of the previous trial.
Following is my present code:

<tr align="center">
<td align="right"> Error Code</td>
<td align="left"> <input type = "text" name = "erCode" value = " "></td>
<td > &nbsp; &nbsp; </td>
<td> &nbsp; &nbsp; </td>
</tr>

This code snippet is in the HTML part of the page and I had assumed that by giving the field a blank for a value, the field would appear to be empty, which is what I want. However, when I click the "Reload Page" button, the last value is NOT cleared (it remains at, say, 4).

I suspect I am overlooking something simple.

Looking forward to reading your suggestions.


David

You can clear the fields without reloading the form by keeping a 'RESET' button on your page.

<html>
<head>
<title>Sample</title>
<script type="text/javascript">
    function fillValue(frm)
    {
        frm.err.value = "ERROR";
    }
</script>
</head>
<body>
    <form name="frm">
    <label for="error">Error</label>
    <input type="text" id="err" name="err" />
    <br />
    <input type="button" value = "Calculate" onclick="fillValue(this.form);"/>
    <br />
    <input type="reset" value="reload" />
    </form>
</body>
</html>

Or if reloading is necessary, do something like:

<html>
<head>
<title>Sample</title>
<script type="text/javascript">
    function fillValue(frm)
    {
        frm.err.value = "ERROR";
    }
    function clearAndReload(frm)
    {    
        location.reload();
        frm.reset();
    }
</script>
</head>
<body>
    <form name="frm">
    <label for="error">Error</label>
    <input type="text" id="err" name="err" />
    <br />
    <input type="button" value = "Calculate" onclick="fillValue(this.form);" />
    <br />
    <input type="button" value="Reload" onclick="clearAndReload(this.form);" />
    </form>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.