...

View Full Version : Localstorage problem.



optimizer123
11-01-2012, 02:34 PM
http://www.screenr.com/78s7

As you can see whenever I click on the reserve button it doesnt save it.

I got a new code here:


function storeIt() {
var theSeats = document.getElementsByClassName('allseats')[0].getElementsByTagName('div');
var theArray = [];
for(i=0; i<theSeats; i++) {
if(theSeats[i].className=='zwart') {
// alert(theSeats[i].className);
theArray.push(1);
} else {
// alert(theSeats[i].className);
theArray.push(0);
window.localStorage.setItem(theSeats[i],1);
}
}
if(window.localStorage) window.localStorage.seats = theArray;
}



and here in my html:


<input type="button" value="Reserveer" onclick= "storeIt(); alert('Bedankt voor uw reservering.\nUw reserveringscode is: ' + Math.floor(Math.random()*(10000000 - 100000 + 1))+'\n\nU wordt nu doorgestuurd naar de homepagina.')">

I gave all the seats the classname allseats so it should work.. but why doesnt it?

sunfighter
11-01-2012, 06:24 PM
What are you expecting to get with this?

var theSeats = document.getElementsByClassName('allseats')[0].getElementsByTagName('div'); It doesn't return anything. If your trying to get the elements that have a class of 'allseats' use this:

var theSeats = document.getElementsByClassName('allseats');
And most importantly, to use theSeats in a for loop you need to access it's length, theSeats.

for(i=0; i<theSeats.length; i++) {

PS. you did not give us your html code, just a button.

optimizer123
11-01-2012, 06:39 PM
thanks for helping :)

HTML:


<html>
<head>
<link rel = stylesheet type = 'text/css' href = "reservering3.css" />
<script type = "text/javascript" src = 'reservering3.js'>
</script>
</head>
<body>
<center>
<h2><center>Reserveren</center></h2>
<p> </p>
<div style="position: relative; width: 450px; height: 300px; border: 1px solid black" class="allseats" />
<div class="geenstoel"></div>
<div class="geenstoel"></div>
<div class="geenstoel"></div>
<div class="geenstoel"></div>
<div id="blauw1" class = "blauw" onclick = "res(this.id)"></div>
<div id="blauw2" class = "blauw" onclick = "res(this.id)"></div>
<div id="blauw3" class = "blauw" onclick = "res(this.id)"></div>
<div id="blauw4" class = "blauw" onclick = "res(this.id)"></div>
</div>
<p></p>
<div style="width: 264px; height: 20px; border: 1px solid black ;background: gray">Scherm</div>
<br>
<div id='seatcount' style="width: 150px; height: 20px; border: 1px solid black ;background: white"></div>
<br>
<div id='seatcounter' style="width: 150px; height: 20px; border: 1px solid black ;background: white"></div>
<p></p>
<p></p>
<a href="home.html">
<input type="button" value="Reserveer" onclick= "storeIt(); alert('Bedankt voor uw reservering.\nUw reserveringscode is: ' + Math.floor(Math.random()*(10000000 - 100000 + 1))+'\n\nU wordt nu doorgestuurd naar de homepagina.')">
</a>
</center>
</div>
</body>
</html>

Code was too long so i only post a few seats



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum