Link to home
Start Free TrialLog in
Avatar of arendt73
arendt73

asked on

Reset button only clears specific fields on form

I have a RESET button on my form that clears all data/entered selected.  However, is it possible to only clear a select few fields and not all of them?  I would like to keep the Name and Report Date fields alone but clear the remainder of the fields (Client, Business, City, and Manager)?

Attached is my RESET button code.

Thank you.
<input name="Button" type="button" class="red" id="Reset" value="RESET" onClick="this.form.reset()" >

Open in new window

Avatar of ChetOS82
ChetOS82
Flag of United States of America image

You would have to manually clear the value of the fields you want to clear.  There is no way to control what the reset method clears.
Avatar of Justin Mathews
Justin Mathews

Something like:

<input name="Button" type="button" class="red" id="Reset" value="RESET" onClick="myreset(this.form)" >

Then define JS function myreset() as:

function myreset(frm)
{
  for (var i=0; i < frm.elements.length; i++)
    if (frm.elements[i].type=='text' && "Client|Business|City|Manager".indexOf(frm.elements[i].name) < 0)
       frm.elements[i].value="";
}
Avatar of arendt73

ASKER

I am attempting jmatix's comment.  Please see attached (error message).

Line 164 contains the input button information (below).

<input name="Button" type="button" class="red" id="Reset" value="RESET" onClick="myreset(this.form)" >
test.jpg
Can you post your code?
try
<input name="Button" type="button" class="red" id="Reset" value="RESET" onClick="javascript:myreset(this.form);"
ASKER CERTIFIED SOLUTION
Avatar of arendt73
arendt73

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you just wanted to clear all the information you could have just done:

<input type="reset" value="RESET" />
Discovered it was easier refreshing webpage.