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.
Attached is my RESET button code.
Thank you.
<input name="Button" type="button" class="red" id="Reset" value="RESET" onClick="this.form.reset()" >
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.
Similar questions here :
https://www.experts-exchange.com/questions/10192930/Clear-Forms.html
https://www.experts-exchange.com/questions/21898418/Clearing-a-form.html
https://www.experts-exchange.com/questions/22099819/Needing-a-Reset-function-to-clear-certain-fields-of-a-calculated-form.html
https://www.experts-exchange.com/questions/10307015/How-to-clear-partial-field-data.html
https://www.experts-exchange.com/questions/10066942/Add-reset-button-without-resetting-certain-fields.html
https://www.experts-exchange.com/questions/10192930/Clear-Forms.html
https://www.experts-exchange.com/questions/21898418/Clearing-a-form.html
https://www.experts-exchange.com/questions/22099819/Needing-a-Reset-function-to-clear-certain-fields-of-a-calculated-form.html
https://www.experts-exchange.com/questions/10307015/How-to-clear-partial-field-data.html
https://www.experts-exchange.com/questions/10066942/Add-reset-button-without-resetting-certain-fields.html
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=='te xt' && "Client|Business|City|Mana ger".index Of(frm.ele ments[i].n ame) < 0)
frm.elements[i].value="";
}
<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=='te
frm.elements[i].value="";
}
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
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:myrese t(this.for m);"
<input name="Button" type="button" class="red" id="Reset" value="RESET" onClick="javascript:myrese
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you just wanted to clear all the information you could have just done:
<input type="reset" value="RESET" />
<input type="reset" value="RESET" />
ASKER
Discovered it was easier refreshing webpage.