JSFiddle - React, Tailwind, and code Playground
HTML
<form name="frm1" method="post">
<table>
<tr><td>Enter Your Name:</td><td><input type="text" id="name" name="name"></td></tr> <tr><td>Enter Your Age:</td><td><input type="text"id ="age" name="age"></td></tr>
<tr>
<td></td><td><a href="page2.html"><input type="button" id ="nextButton" value="Next"></a></td> </table> </form>
JavaScript
// Check if local storage has previously stored value
// If there are values then populate relevent field with value.
document.addEventListener("DOMContentLoaded", function(event) {
var getStoredName = localStorage.name;
var getStoredAge = localStorage.age;
console.log(getStoredName ,getStoredAge);
if(getStoredName !==undefined || getStoredAge !== undefined){
document.getElementById("name").value=getStoredName;
document.getElementById("age").value=getStoredAge;
}
})
// Set local storage on click of next button
var getNextButton = document.getElementById("nextButton"); getNextButton.addEventListener("click",function(){
localStorage.name=document.getElementById("name").value;
localStorage.age=document.getElementById("age").value;
})