You are viewing limited content. For full access, please sign in.

Question

Question

Clear all form field data when different drop down is selected

asked on May 30, 2018

I'm looking for a way using JavaScript to clear all the data in fields on a form if a different drop down is selected. I have a reset button in place using : 

<input type="reset">

But I am lacking the correct code to automatically click that button upon a change to the drop down. Does anyone have a quick fix?
 

1 0

Replies

replied on May 30, 2018 Show version history

First, add a custom CSS class to the dropdown (something like "resetTrigger" ) then add an ID or class to your reset button so you can reference it more easily in the code (something like id="resetButton").

<input id="resetButton" type="reset">

Then add the following JavaScript/JQuery

$(document).ready(function(){  
  $('.resetTrigger select').change(function(){
    $('#resetButton').click();
  });
});

That will get you started, but you'll need to make adjustments if it only resets when certain options are selected or anything else along those lines.

1 0
replied on September 21, 2022

Could you add the additional lines for clearing fields?  I have fields on a form that populate with dollar amounts, would like to reset those to zero if the applicant changes their selection in the dropdown.

Thank you in advance for your help.

Christine

0 0
replied on September 21, 2022

Add a class to all the currency fields you want to reset, then use the following line:

$('.currencyReset input').val('0').change();

Just replace "currencyReset" with whatever class you apply to those fields.

If you want them empty rather than 0, use .val('') instead

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.