I want to send the data using sessionStorage to the other page, it works at first. However, when I call another function to make the dropdown list, only one function that works depends on the position.
I have tried to change the position of the function in function init()
, and I have tried to check whether the sessionStorage value is sent or not using alert(sessionStorage.title); but when I call the selection function, the sessionStorage value is undefined.
function init(){
alert (sessionStorage.title);
extractDataReceived();
selection();
if (window.location != "enquiry.html"){
sessionStorage.clear();
}
datatransfer = document.getElementById("datatransfer");
datatransfer.onsubmit = storeDataReceived();
}
function storeDataReceived(){
sessionStorage.title = document.getElementById("title").value;
}
function extractDataReceived(){
if (sessionStorage.title != undefined){
document.getElementById("subject").textContent = sessionStorage.title;
}
}
function selection(){
var select = document.getElementById("iselect");
var options = ["(CAPSULE) Creatista Royale", "(CAPSULE) Lattissima Tactile", "(CAPSULE) Slique Limousine", "(CAPSULE) Ala Doby", "(CAPSULE) Essenza Minima", "(CAPSULE) Velour Retro",
"(BEAN-TO-CUP) De'Longhi Magnifica ESAM 4200.S", "(BEAN-TO-CUP) Melitta Caffeo SOLO and perfect milk", "(BEAN-TO-CUP) Gaggia Brera", "(BEAN-TO-CUP) Cuisinart One Cup Grind and Brew", "(BEAN-TO-CUP) Breville Barista Express",
"(MANUAL) The Barista", "(MANUAL) VGEBY Espresso Coffee Maker", "(MANUAL) Philips Seaco Poemia", "(MANUAL) Delonghi ECP35,31", "(MANUAL) Gemilai Italia"];
for(var i = 0; i < options.length; i++ ){
var opt = options[i];
var ele = document.createElement("option");
ele.textContent = opt;
ele.value = opt;
select.appendChild(ele);
}
}
window.onload = init;
I expected that the sessionStorage value will be the title not undefined and I expected to have the dropdown list or select option to work.