Reset button only clears specific fields on form

arendt73
arendt73 used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
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.
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="";
}
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Author

Commented:
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);"
Commented:
I have decided to use the refresh of the page.  Although it clears all information to default, it works.

Issue I had is before I added the Form Action to the page, I was able to have two submit buttons. One to submit the information and the other to reset/clear the fields. But I discovered that after adding the form action, the reset button was also submitting the information.

Commented:
If you just wanted to clear all the information you could have just done:

<input type="reset" value="RESET" />

Author

Commented:
Discovered it was easier refreshing webpage.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial