Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2012
    Location
    Basement
    Posts
    88
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Localstorage problem.

    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:

    Code:
    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:

    Code:
    <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?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,206
    Thanks
    23
    Thanked 605 Times in 604 Posts
    What are you expecting to get with this?
    Code:
     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:
    Code:
    var theSeats = document.getElementsByClassName('allseats');
    And most importantly, to use theSeats in a for loop you need to access it's length, theSeats.
    Code:
    for(i=0; i<theSeats.length; i++) {
    PS. you did not give us your html code, just a button.

  • #3
    New Coder
    Join Date
    Oct 2012
    Location
    Basement
    Posts
    88
    Thanks
    9
    Thanked 0 Times in 0 Posts
    thanks for helping

    HTML:

    Code:
    <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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •