var data = {
'Harold' : {
'Class' : '11',
'Score' : '89%'
},
'Hadley' : {
'Class' : '8',
'Score' : '94%'
}
};
function updateData() {
var name = document.getElementById('name').value;
var clas = document.getElementById('class').value;
var score = document.getElementById('score').value;
if(name === 'Harold') {
alert('Student already exists');
document.getElementById('demo').innerHTML = data['Harold']['Class'];
document.getElementById('demo2').innerHTML = data['Harold']['Score']
} else if(name === 'Hadley'){
alert('Student already exists');
document.getElementById('demo').innerHTML = data['Hadley']['Class'];
document.getElementById('demo2').innerHTML = data['Hadley']['Score'];
} else {
if(clas !== '') {
if(score !== '') {
data[name] = {'Class' : clas, 'Score' : score };
}
alert('Student added to data')
}
}
}
function retrieveData() {
var student = document.getElementById('newstudent').value;
if(student in data) {
console.log(data[student]);
} else {
console.log('Artist not available.Please add it.')
}
}
I have created a small page that adds data of a student( class and score ) and displays it below when searched.
The details added are added to the variable ‘data’ which is an object.
The problem is when i reload the page the saved data is lost.
How can I save data without losing it after I reload the page??