<!DOCTYPE html>
<html>
<head>
<title>reset form in jqery</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<h1 align="center">Type something in Input field and click "Reset this form" button</h1>
<form class="my-form">
<input type="text" name="firstname" placeholder="Your first name">
<input type="text" name="lastname" placeholder="Your last name">
<input type="email" name="email" placeholder="Type email here">
<input type="submit" value="Register">
</form>
<br><br>
<button class="reset-btn">Reset this form</button>
<script>
$(document).ready(function(){
$(".reset-btn").click(function(){
$(".my-form").trigger("reset");
});
});
</script>
</body>
</html>
Live example
Type something in Input field and click "Reset this form" button
Default values set to the INPUT field using value="something"
can not be reset by this method.
More posts:-
- https://jaischool.com/questions/javascript/show-window-open-popup-in-center-of-the-user-screen.html
- https://jaischool.com/error/failed-to-load-resource-neterr_http2_protocol_error-one-possible-solution.html
- https://jaischool.com/javascript-lang/calculate-width-and-height-ratio-of-image.html
- https://jaischool.com/javascript-lang/convert-rgb-code-into-hex-code.html
Publish A Comment