I have 2 webpages. One called Create An Event and the other Calendar Of Events. In Create An Event, a form is used to allow users' inputs. The inputs are then stored to local storage with the following function:
document.addEventListener("DOMContentLoaded", docIsReady);
var CreateEvent;
function docIsReady() {
CreateEvent = localStorage.getItem("CreateEvent");
if (CreateEvent == null) {
CreateEvent = [];
} else {
CreateEvent = JSON.parse(CreateEvent);
}
}
function saveToStorage() {
var one;
var nameofevent = document.getElementById("name").value;
var pList = document.getElementsByName("pos");
var positions = [];
for (i = 0; i < pList.length; i++) {
positions.push(pList[i].value);
console.log(pList[i].value);
}
//for (i=0; i<positions.length; i++){
//console.log(positions[i].value);
//}
var venue = document.getElementById("venue").value;
var date = document.getElementById("date").value;
var starttime = document.getElementById("timeStart").value;
var endtime = document.getElementById("timeEnd").value;
var contact = document.getElementById("contact").value;
var email = document.getElementById("email").value;
var desc = document.getElementById("desc").value;
one = {
"name": nameofevent,
"pos": positions,
"venue": venue,
"date": date,
"timeStart": starttime,
"timeEnd": endtime,
"contact": contact,
"email": email,
"desc": desc
};
CreateEvent.push(one);
localStorage.setItem("CreateEvent", JSON.stringify(CreateEvent));
return false;
}
I made CreateEvent an array so as to store the multiple inputs because there cannot be only one event created. Now, I need to display the NAME of the event in a table on Calendar Of Events. As its a calendar, the events will be sorted by the months. However, I don't know how to access the "date" and "name" value in each of the objects stored in the array. How do I retrieve the values in objects?