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