Reset the values of a form using jQuery

To reset the values of a form using jQuery, you can use the reset method. This method resets the form fields to their default values. Here is an example:

HTML:

<form id="myForm">
  <input type="text" name="name" value="John">
  <input type="text" name="email" value="john@example.com">
  <button type="button" id="resetBtn">Reset</button>
</form>

JavaScript:

$(document).ready(function() {
  $('#resetBtn').click(function() {
    $('#myForm')[0].reset();
  });
});

In the above example, when the user clicks the "Reset" button, the values of the input fields with name="name" and name="email" will be reset to their default values. The reset method is called on the form element with id myForm.

Note that the reset method only works on form elements, not on individual input fields.

Komentar

Postingan populer dari blog ini

Node.js Telegram Bot API send an image with text

Node.js Telegram BOT retrieve data from API

WhatsApp Web login QR code in an HTML page using whatsapp-web.js