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