Skip to content Skip to sidebar Skip to footer

Clearing Form Input Fields In Bootstrap?

Does Bootstrap offer anything for clearing form input fields via a button? Or do I need to roll my own through jquery? From this post jQuery Validate resetForm() doesn't reset the

Solution 1:

You can use reset method (this is DOM element method, it is not jQuery object method), like this

$('form').get(0).reset() // or $('form')[0].reset()

Solution 2:

Similar to other answers, if you want to reset the form (not necessarily clear it) you can use the following:

<button type="reset">

It's a little cleaner than embedding jQuery or javascript calls in the onclick...

Solution 3:

This worked for me (clearing the fields, not just resetting the form fields to inital value):

$(':input').val('');

but it seems to have side effects like submitting the form.

Post a Comment for "Clearing Form Input Fields In Bootstrap?"