Not able to redirect to "index.html" after doing something with data. Find HERE in my code.
form syntax: ___ <body> <form id="formId" onsubmit="addStudentData()"></form> </body> __ Scripts: __ function addStudentData() { let name = document.getElementById('sname').value; let id = document.getElementById('sid').value; let year = document.getElementById('syear').value; let stream = document.getElementById('sstream').value; /* Form validation -- the fields should not be empty. */ if (name == null || name == "", id == null || id == "", year == null || year == "", stream == null || stream == "") { alert("Please fill all required fields."); return false; } /* Making a JSON object using the form values */ let studentObj = { 'name': name, 'year': year, 'stream': stream }; /* Pushing record to sessionStorage after stringify JSON Object*/ sessionStorage.setItem(id, JSON.stringify(studentObj)); /* Redirecting back to home page*/ alert("Done. Press OK, redirect to home page."); //HERE HERE HERE window.location = "index.html"; }