I am looking for a way to clear all elements found within an HTML form contained inside a Bootstrap modal without refreshing the page.
Currently:
The user enters data and closes the modal.
When the user re-opens the modal, the previously entered data still remains.
How can I completely clear all elements within the form during the close event of the modal dialog so that when the user re-opens it, they always get fresh clean inputs & etc?
reset is dom build-in funtion, you can also use $(this). find('form')[0]. reset();
You can easily reset all form values using the HTML button using <input type=”reset”> attribute. Clicking the reset button restores the form to its original state (the default value) before the user started entering values into the fields, selecting radio buttons, checkboxes, etc.
To clear an input field after submitting:Add a click event listener to a button. When the button is clicked, set the input field's value to an empty string. Setting the field's value to an empty string resets the input.
Bootstrap Modal Form Bootstrap modal forms are displayed-on-action pop-up forms that are used for gathering data from website visitors and to register or log users. Using them alongside valuable content might bring a lot of business value to your project.
In Bootstrap 3 you can reset your form after your modal window has been closed as follows: $ ('.modal').on ('hidden.bs.modal', function () { $ (this).find ('form').reset (); });
Change the size of the modal by adding the .modal-sm class for small modals or .modal-lg class for large modals. Add the size class to the <div> element with class .modal-dialog: By default, modals are medium in size. For a complete reference of all modal options, methods and events, go to our Bootstrap JS Modal Reference.
When the user re-opens the modal, the previously entered data still remains. How can I completely clear all elements within the form during the close event of the modal dialog so that when the user re-opens it, they always get fresh clean inputs & etc?
In Bootstrap 3 you can reset your form after your modal window has been closed as follows:
$('.modal').on('hidden.bs.modal', function(){ $(this).find('form')[0].reset(); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With