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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Local storage for table

    For a school project I need to make a booking system for a cinema, so people can select seats where they want to sit.

    One requirement is that if someone booked a chair, someone ele shouldn't be able to book it anymore.

    My idea was to add a class to the selected chairs when you click "Buy tickets" on the bottom of the page, but how can I save these classes, my professors say I should use HTML 5 storage, but they refuse to help me any further.

    This is a part of what I already have now:

    Code:
    <script>
     var total = 0;
     var countBlauw = 0;
     var countOranje = 0;
     var countRood = 0;
     $(document).ready(function(){
         $(".blauw").toggle(function () {
           $(this).removeClass("blauw").addClass("select");
     countBlauw++;
     total+=7.5;
     calculateTotal();
     }, function() { 
           $(this).removeClass("select").addClass("blauw");
     countBlauw--;
           total-=7.5;
     calculateTotal();
         });
     $(".oranje").toggle(function () {
           $(this).removeClass("oranje").addClass("select");
     countOranje++;
     total+=10;
     calculateTotal();
     }, function() {
           $(this).removeClass("select").addClass("oranje");
     countOranje--;
           total-=10;
     calculateTotal();
         });
     $(".rood").toggle(function () {
           $(this).removeClass("rood").addClass("select");
     countRood++;
           total+=15;
     calculateTotal();
     }, function() {
           $(this).removeClass("select").addClass("rood");
     countRood--;
           total-=15;
     calculateTotal();
         });
     });
     </script> 
            <script>
            function calculateTotal()
            {
                var divobj = document.getElementById('totalPrice');
                divobj.style.display='block';
                divobj.innerHTML = "Prijs €"+total+"<br /> Aantal blauwe stoelen: "+countBlauw+"<br /> Aantal oranje stoelen: "+countOranje+"<br /> Aantal rode stoelen: "+countRood;
            
            }
            </script> 
            
            <table style="empty-cells: hide; border-collapse:separate; border-spacing:2px; border-style:solid;" border="0">
              <tr>
                <td class="leeg"></td>
                <td class="leeg"></td>
                <td class="blauw">&nbsp;</td>
                <td class="blauw">&nbsp;</td>
                <td class="blauw">&nbsp;</td>
                <td class="blauw">&nbsp;</td>
                <td class="blauw">&nbsp;</td>
                <td class="blauw">&nbsp;</td>
                <td class="blauw">&nbsp;</td>
                <td class="blauw">&nbsp;</td>
                <td class="leeg"></td>
                <td class="leeg"></td>
              </tr>
                And so forth.
    
    
            <script>
     $(window).load( function() {
      document.getElementById('totalPrice').innerHTML = "Prijs €"+total+"<br /> Aantal blauwe stoelen: "+countBlauw+"<br /> Aantal oranje stoelen: "+countOranje+"<br /> Aantal rode stoelen: "+countRood;
     });
     </script>
     <div id="totalPrice"></div>
    Is it possible to save the classes added with .addClass() to local or session storage? It's should only be a simulation, so it doesn't matter if someone on another computer (or with an other browser) can book the same seat.

    I can also give every chair an id, if that makes it easier.

    Could someone please give me some advice?

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Wow, that one sounds familiar ... see LocalStorage

  • #3
    New Coder
    Join Date
    Oct 2012
    Location
    Basement
    Posts
    88
    Thanks
    9
    Thanked 0 Times in 0 Posts
    wow that's creepy o.O

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,016
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by optimizer123 View Post
    wow that's creepy o.O
    Notice both OPs are Dutch - using the word "chairs" (stoelen) rather than the correct English in this context "seats".
    Same school?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New Coder
    Join Date
    Oct 2012
    Location
    Basement
    Posts
    88
    Thanks
    9
    Thanked 0 Times in 0 Posts
    ^ probably, idk him though


  •  

    Tags for this Thread

    Posting Permissions

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