Jesus A. Jesus A. - 17 days ago 7
jQuery Question

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

Answer

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

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

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

Comments