1

I am trying to reset form inputs by :

$("#form_employee_job")[0].reset();

The inputs still filled and console return undefined

What i'm missing ?

enter image description here

Yunis Hawwash
  • 98
  • 2
  • 13

3 Answers3

1

Have a look at this fiddle https://jsfiddle.net/yn2xeq6z/1/

If your form id isform_employee_job then everything should work as expected. All input field of Form will be cleared.

Mohd Asim Suhail
  • 2,176
  • 1
  • 16
  • 23
1

Maybe you're missing something else, outside of the code you've posted here?

Here's a working jsfiddle that might help you on your way. This example will reset the form when you press the button.

HTML

<form id='form_employee_job'>
  <input type='text'/>
</form>
<button id="btn">reset</button>

JS

$(document).ready(function() {
  $("#btn").on("click", function() {
    $("#form_employee_job")[0].reset();
  });
});
Niklas
  • 13,005
  • 23
  • 79
  • 119
1

I believe that your form might have POST data in the fields with the POST/GET request. In this case, form reset will not work.

I am not 100% sure if this is bug or the way it works.

If you have programmatically assined some values to the input, it might be able to not reset.

In order to achieve reset, you can empty the form inputs.

$(':input','#myform')
    .not(':button, :submit, :reset, :hidden')
    .val('')
    .removeAttr('checked')
    .removeAttr('selected');

Please see this post Resetting a multi-stage form with jQuery

Irfan Ahmed
  • 9,136
  • 8
  • 33
  • 54