lundi 19 mars 2018

Not able to redirect to another webpage in my project

I have a form:

<form id="formId" onsubmit="addStudentData()"></form>

And javascript function :

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;

/* 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.href = "index.html"
}

I don't understand why my javascript function is not opening index.html after storing the data in sessionStorage. Also, if you can, state another way to do it.




Aucun commentaire:

Enregistrer un commentaire