optimizer123
11-04-2012, 06:40 PM
It looks like this is not working:
HTML:
<div id="zaal3"style="position: relative; width: 450px; height: 300px; border: 1px solid black" id="allseats"/>
JS:
window.onload = function() {
if(window.localStorage && window.localStorage.seats) {
var theArray = JSON.parse(window.localStorage.seats);
var allestoelen = document.getElementById('allseats').getElementsByTagName('div');
for(i=0; i<allestoelen.length; i++) {
if(theArray[i]===1) allestoelen[i].className="blocked";
}
}
};
function storeIt() {
var allestoelen = document.getElementById('allseats').getElementsByTagName('div');
//alert(allestoelen.length);
var theArray = [];
for(i=0; i<allestoelen.length; i++) {
if(allestoelen[i].className == "zwart") {
theArray.push(1);
} else {
theArray.push(0);
}
}
var jsonArray = JSON.stringify(theArray);
window.localStorage.seats = jsonArray;
console.log(jsonArray);
return false;
}
Someone told me having 2 id's won't work (Id zaal3 & Id allseats in 1 line).
I tried changing 'allseats' in JS to 'zaal3' but it dont seem to be working. What am i doing wrong?
HTML:
<div id="zaal3"style="position: relative; width: 450px; height: 300px; border: 1px solid black" id="allseats"/>
JS:
window.onload = function() {
if(window.localStorage && window.localStorage.seats) {
var theArray = JSON.parse(window.localStorage.seats);
var allestoelen = document.getElementById('allseats').getElementsByTagName('div');
for(i=0; i<allestoelen.length; i++) {
if(theArray[i]===1) allestoelen[i].className="blocked";
}
}
};
function storeIt() {
var allestoelen = document.getElementById('allseats').getElementsByTagName('div');
//alert(allestoelen.length);
var theArray = [];
for(i=0; i<allestoelen.length; i++) {
if(allestoelen[i].className == "zwart") {
theArray.push(1);
} else {
theArray.push(0);
}
}
var jsonArray = JSON.stringify(theArray);
window.localStorage.seats = jsonArray;
console.log(jsonArray);
return false;
}
Someone told me having 2 id's won't work (Id zaal3 & Id allseats in 1 line).
I tried changing 'allseats' in JS to 'zaal3' but it dont seem to be working. What am i doing wrong?