Jesus A.
Jesus A.

Reputation: 69

Clear one filed of the form after submit with jQuery

I read alot of answers but all of them talk about reset all form, that I want to do is reset only specific fields for example I have this input and this select:

 <div class="col-md-12 ">
    <input type="text" id="observedNEmployees" name="observedNEmployees" class="form-control">
 </div>

<select class="form-control" id="severityFactorEmployee" name="severityFactorEmployee">
               <option value="">Select...</option>
               <option value="0"></option>
               <option value="0"></option>
</select>

So for first one I try to clear when submit button is clicked liked as:

$("#observedNEmployees").attr('');

And second one:

$("#severityFactorEmployee").trigger("change");

But they didn´t work

Note*: Select list need to reset to first option

Upvotes: 0

Views: 30

Answers (1)

Scott
Scott

Reputation: 867

To reset your form, use the following for the respective form input options.

Input Box $("#observedNEmployees").val("");

Select Box $("#severityFactorEmployee").prop('selectedIndex', 0);

Upvotes: 2

Related Questions