Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 onFocus validation, there seems to be a resetForm() method coming from jquery but I always get a object doesn't support method when I try to access that method.

like image 528
4thSpace Avatar asked Jan 07 '15 18:01

4thSpace


People also ask

How do I clear all inputs in a form?

To clear all the input in an HTML form, use the <input> tag with the type attribute as reset.

How do I clear pop up data?

Scroll down to the Privacy and Security Section. Click Clear browsing data at top of Privacy and security section. At the Time range drop-down box, select All time. Make sure the option Cached images and files is checked and remove all other checkmarks.


2 Answers

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()
like image 122
Oleksandr T. Avatar answered Sep 27 '22 17:09

Oleksandr T.


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...

like image 27
Mir Avatar answered Sep 27 '22 18:09

Mir