Refresh page after clearing all form fields in jQuery?

To refresh page, use the location.reload() in JavaScript. The sample JavaScript code is as follows −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<link rel="stylesheet" href="//">
<script src=""></script>
<script src=""></script>
<label for="userId">
<input type="text" >
<label for="pass">
<input type="password" >
<button type="submit" id="RefreshPage" >Refresh Page</button>
   $('#RefreshPage').click(function() {

To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.


This will produce the following output −

After filling the form, the snapshot is as follows −

When you click the button “Refresh Page”, the page will refresh and the following output is visible −

Updated on: 01-Sep-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started