How to reset form input element on click
Created at 23-Aug-2021 ,
By samar
How to reset form input element on click
Through the use of the programming language, we will work together to solve the "How to reset form input element on click" puzzle in this lesson.
You can reset the form input element on click using jQuery by assigning null value to it. Here we can use jquery / javascript element selector and after that assign null value using .val() method in jQuery and .value method in javascript.-
Reset form input element by name on click using jQuery
<form id="formId" method="POST" action="../"> <input type="text" name="first_name" value="w3codegenerator.com" /> </form> <button type="button"> Click button </button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('button').on('click', function(){ $('#formId').find('input[name="first_name"]').val(''); }); }) </script>
-
Reset form on click button using reset() method in jQuery
<form id="FormId"> <input type="text" name="name" /> </form> <button type="button"> Reset Form </button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function() { $("button").click(function() { $("#FormId")[0].reset() }); }); </script>
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Jquery
- Preview image in base64 format using jQuery on change input file
- Validate form using jQuery
- How to preview image before uploading in jQuery
- Show and hide target element on click button using javascript/jquery
- Uncaught TypeError: $.ajaxSetup is not a function
- Append method to add text to body not working
- How to create read more in jquery
- Jquery.validate.min.js:4 Uncaught TypeError: Cannot read properties of undefined (reading 'mode')
- Show loading icon on click submit button in jQuery
- Preview image in BLOB URL format on choose file in jQuery
- Jquery-3.6.0.min.js CDN link
- Ajax done fail ajaxcomplete in not a function
- (index):128 Uncaught TypeError: MobileNumberVal.test is not a function
- Execute function after Ajax call is complete
- How to validate input type file size in jQuery for multiple records
- JQuery find text and show as bold in html page
- How to check object is empty or not in jQuery
- How to find closest upper element and append html to below it in jquery
- Add and remove input fields on click button using jQuery
- How to use and purpose of localstorage in javascript
- Enable click event on appended element using jQuery
- Get the href link on click anchor in javascript
- How to pass javascript variable to laravel route on ajax call
- How to get closest form input value in jQuery
- Mixed Content: The page at 'https://w3codegenerator.com/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint