
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
- How to use and purpose of localstorage in javascript
- Preview image in base64 format using jQuery on change input file
- How to create read more in jquery
- Append method to add text to body not working
- Preview image in BLOB URL format on choose file in jQuery
- Execute function after Ajax call is complete
- How to remove Choose File button in jquery
- How to preview image before uploading in jQuery
- How to check ajax request is completed in jQuery
- Show loading icon on click submit button in jQuery
- How to get closest form input value in jQuery
- Ajax for multiple form
- Jquery-3.6.0.min.js CDN link
- How to check object is empty or not in jQuery
- Add and remove input fields on click button using jQuery
- Mixed Content: The page at 'https://w3codegenerator.com/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint
- Ajax done fail ajaxcomplete in not a function
- Uncaught TypeError: $.ajaxSetup is not a function
- JQuery find text and show as bold in html page
- Enable click event on appended element using jQuery
- Jquery.validate.min.js:4 Uncaught TypeError: Cannot read properties of undefined (reading 'mode')
- Uncaught TypeError: $.ajax is not a function
- Show and hide target element on click button using javascript/jquery
- JQuery append html to below the target element
- (index):128 Uncaught TypeError: MobileNumberVal.test is not a function