display the chosen choices from the jquery tool

I have implemented a Jquery movie seat selection plugin on my jsp website successfully. It allows users to select seats with ease.

However, the issue I am facing is that due to my limited knowledge of Jquery, I am unable to display the selected seats by the user on my jsp page.

I kindly request assistance in showing the users' selected seats on the jsp page so that I can save them in my derby database for future reference.

Here is the HTML snippet:

  <div class="demo">
    <div id="seat-map">
        <div class="front">SCREEN</div>                
    </div>

    <div class="booking-details">


        <p>Seat: </p>
        <ul id="selected-seats"></ul>
        <p>Tickets: <span id="counter">0</span></p>
        <p>Total: <b>Rs.<span id="total">0</span></b></p>

                    <a href="ticketValidation"><input type="button" value="BUY" class="checkout-button"/></a>

        <div id="legend"></div>
    </div>
    <div style="clear:both"></div>

Jquery :

      </style>

    <script>
         var price = 120; //price
$(document).ready(function() {
var $cart = $('#selected-seats'), //Sitting Area

$counter = $('#counter'), //Votes
$total = $('#total'); //Total money

var sc = $('#seat-map').seatCharts({
    map: [  //Seating chart
        'aaaaaaaaaa',
        'aaaaaaaaaa',
        'aaaaaaaaaa',
        'aaaaaaaaaa',
        'aaaaaaaaaa',
        'aaaaaaaaaa',
        'aaaaaaaaaa',
        'aaaaaaaaaa',
        'aaaaaaaaaa',

    ],
    naming : {
        top : false,
        getLabel : function (character, row, column) {
            return column;
        }
    },
    legend : { //Definition legend
        node : $('#legend'),
        items : [
            [ 'a', 'available',   'Avail' ],
            [ 'a', 'unavailable', 'Sold']
        ]                  
    },
    click: function () { //Click event
        if (this.status() == 'available') { //optional seat
            $('<li>R'+(this.settings.row+1)+' S'+this.settings.label+'</li>')
                .attr('id', 'cart-item-'+this.settings.id)
                .data('seatId', this.settings.id)
                .appendTo($cart);

            $counter.text(sc.find('selected').length+1);
            $total.text(recalculateTotal(sc)+price);

            return 'selected';
        } else if (this.status() == 'selected') { //Checked
                //Update Number
                $counter.text(sc.find('selected').length-1);
                //update totalnum
                $total.text(recalculateTotal(sc)-price);

                //Delete reservation
                $('#cart-item-'+this.settings.id).remove();
                //optional
                return 'available';
        } else if (this.status() == 'unavailable') { //sold
            return 'unavailable';
        } else {
            return this.style();
        }
    }
});
//sold seat
sc.get(['1_2', '4_4','4_5','6_6','6_7','8_5','8_6','8_7','8_8', '10_1', '10_2']).status('unavailable');
});
//sum total money
function recalculateTotal(sc) {
var total = 0;
sc.find('selected').each(function () {
    total += price;
});

return total;
}
</script>

CSS:

<style> 
.front{width: 300px;margin: 5px 32px 45px 32px;background-color:           #f0f0f0; color: #666;text-align: center;padding: 3px;border-radius: 5px;} 
.booking-details {float: right;position: relative;width:200px;height: 450px; } 
.booking-details h3 {margin: 5px 5px 0 0;font-size: 16px;} 
.booking-details p{line-height:26px; font-size:16px; color:#999} 
.booking-details p span{color:#666} 
div.seatCharts-cell {color: #182C4E;height: 25px;width: 25px;line-height:     25px;margin: 3px;float: left;text-align: center;outline: none;font-size: 13px;} 
div.seatCharts-seat {color: #fff;cursor: pointer;-webkit-border-radius:5px;-   moz-border-radius:5px;border-radius: 5px;} 
div.seatCharts-row {height: 35px;} 
div.seatCharts-seat.available {background-color: #B9DEA0;} 
div.seatCharts-seat.focused {background-color: #76B474;border: none;} 
div.seatCharts-seat.selected {background-color: #E6CAC4;} 
div.seatCharts-seat.unavailable {background-color: #472B34;cursor: not-allowed;} 
div.seatCharts-container {border-right: 1px dotted #adadad;width:      400px;padding: 20px;float: left;} 
div.seatCharts-legend {padding-left: 0px;position: absolute;bottom: 16px;} 
ul.seatCharts-legendList {padding-left: 0px;} 
.seatCharts-legendItem{float:left; width:90px;margin-top: 10px;line-height: 2;} 
span.seatCharts-legendDescription {margin-left: 5px;line-height: 30px;} 
.checkout-button {display: block;width:80px; height:24px; line-    height:20px;margin: 10px auto;border:1px solid #999;font-size: 14px; cursor:pointer} 
#selected-seats {max-height: 150px;overflow-y: auto;overflow-x: none;width: 200px;} 
#selected-seats li{float:left; width:72px; height:26px; line-height:26px;    border:1px solid #d3d3d3; background:#f7f7f7; margin:6px; font-size:14px; font-   weight:bold; text-align:center}
</style>

Please lend me your expertise!

Thank you!

Answer №1

If you're looking to create a dialog box with a PDF version of the HTML related to your selected seat when clicking a print button, I recommend using the jQuery dialog plugin (dialog) along with jsPDF.

Here's an example of what the result may look like: https://i.sstatic.net/j6Po3.jpg

Below is the code snippet:

var price = 120; //price
var sc;

//calculate total amount
function recalculateTotal(sc) {
  var total = 0;
  sc.find('selected').each(function () {
    total += price;
  });

  return total;
}

$(function () {
  var $cart = $('#selected-seats'), //Sitting Area

      $counter = $('#counter'), //Votes
      $total = $('#total'); //Total money

  sc = $('#seat-map').seatCharts({
    map: [  //Seating chart
      'aaaaaaaaaa',
      'aaaaaaaaaa',
      'aaaaaaaaaa',
      'aaaaaaaaaa',
      'aaaaaaaaaa',
      'aaaaaaaaaa',
      'aaaaaaaaaa',
      'aaaaaaaaaa',
      'aaaaaaaaaa',

    ],
      naming: {
      top: false,
      getLabel: function (character, row, column) {
      return column;
      }
      },
      legend: { //Definition legend
      node: $('#legend'),
      items: [
      ['a', 'available', 'Avail'],
    ['a', 'unavailable', 'Sold']
    ]
  },
                                 click: function () { //Click event
    if (this.status() == 'available') { //optional seat
      $('<li>R' + (this.settings.row + 1) + ' S' + this.settings.label + '</li>')
      .attr('id', 'cart-item-' + this.settings.id)
      .data('seatId', this.settings.id)
      .appendTo($cart);

      $counter.text(sc.find('selected').length + 1);
      $total.text(recalculateTotal(sc) + price);

      return 'selected';
    } else if (this.status() == 'selected') { //Checked
      //Update Number
      $counter.text(sc.find('selected').length - 1);
      //update totalnum
      $total.text(recalculateTotal(sc) - price);

      //Delete reservation
      $('#cart-item-' + this.settings.id).remove();
      //optional
      return 'available';
    } else if (this.status() == 'unavailable') { //sold
      return 'unavailable';
    } else {
      return this.style();
    }
  }
});
//sold seat
sc.get(['1_2', '4_4', '4_5', '6_6', '6_7', '8_5', '8_6', '8_7', '8_8', '10_1', '10_2']).status('unavailable');


$(':button[value="PRINT"]').on('click', function(e) {
  e.preventDefault();
  if ($('#selected-seats li').length > 0) {
    var doc = new jsPDF();

    var specialElementHandlers = {
      '#selected-seats': function(element, renderer){
        return true;
      }
    };
    doc.fromHTML($('#selected-seats').html(), 15, 15, {
      'width': 170,
      'elementHandlers': specialElementHandlers
    });
    var uriPdf =  doc.output('datauristring');

    $('<div>').prop('id', '_currentDialog').add('<iframe id="_myPdf" type="application/pdf" src="' + uriPdf + '"></iframe>').dialog({
      title: "Selected seat",
      width: 600,
      height: 800,
      close: function (event, ui) {
        $('#_currentDialog').remove();
      }
    });
  } else {
    alert('No selected seat to print!')
  }
});
});
.front {
  width: 300px;
  margin: 5px 32px 45px 32px;
  background-color: #f0f0f0;
  color: #666;
  text-align: center;
  padding: 3px;
  border-radius: 5px;
}

.booking-details {
  float: right;
  position: relative;
  width: 200px;
  height: 450px;
}

.booking-details h3 {
  margin: 5px 5px 0 0;
  font-size: 16px;
}

booking-details p {
  line-height: 26px;
  font-size: 16px;
  color: #999
}

booking-details p span {
  color: #666
}

/* CSS styles continue... */
<link href="js/jquery.seat-chart/jquery.seat-charts.css" rel="stylesheet">
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="js/jquery.seat-chart/jquery.seat-charts.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.min.js"></script>

<div class="demo">
    <div id="seat-map">
        <div class="front">SCREEN</div>
    </div>

    <div class="booking-details">


        <p>Seat: </p>
        <ul id="selected-seats"></ul>
        <p>Tickets: <span id="counter">0</span></p>

        <p>Total: <b>Rs.<span id="total">0</span></b></p>

        <a href="ticketValidation"><input type="button" value="BUY" class="checkout-button"/></a>
        <a href="ticketPrint"><input type="button" value="PRINT" class="checkout-button"/></a>

        <div id="legend"></div>
    </div>
    <div style="clear:both"></div>
</div>

Answer №2

If you're looking to incorporate jQuery into your HTML, the convenient function to use is "html()". For instance, if you wish to add text to a specific div with the id of "legend", simply execute this line of code:

$("#legend").html("<p>whatever message you want to include</p>");

For further guidance on this topic, feel free to visit the following link: w3schools tutorial

I trust this information proves useful in your endeavors.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

VueJS with Vuetify: Issue with draggable cards in a responsive grid

I am currently working on creating a gallery that allows users to rearrange images. To test this functionality, I am using an array of numbers. It is important that the gallery is responsive and displays as a single column on mobile devices. The issue I ...

The computed variable in Vuex does not get updated when using the mapState function

I searched through several posts to find out what I am doing incorrectly. It seems like everything is set up correctly. MOTIVE Based on the value of COMPONENT A, I want to change hide/display content using v-show in DEPENDENT COMPONENT. ISSUE In the T ...

PHP: Communicating Data with JavaScript

What if my PHP script requires some time to complete its operations? How can I keep the client updated on the progress of the operation, such as during a file download where the estimated time and data size need to be communicated? In PHP, calculating all ...

Enable the image to extend beyond the boundaries of its containing div

How can I prevent a div from extending its width, allowing an image to be visible outside of it in IE8? Specifically, my div may be 200px wide while the image is 250px wide. ...

What could be causing the issue with Vite build and npm serve not functioning together?

After shifting from CRA to VITE, I am encountering a problem with serving my app. I successfully build my app using vite build. and can serve it using Vite serve without any issues. However, I want to use npm's serve command. Whenever I run vite bui ...

Problem arises when attempting to display a div after clicking on a hyperlink

I'm encountering an issue with displaying a div after clicking on a link. Upon clicking one of the links within the initial div, a new div is supposed to appear below it. All tests conducted in jsfiddle have shown successful results, but upon transf ...

javascript: update hidden field if date is past January 15th

Having a bit of trouble with this one after a full day! The form contains a hidden field called 'grant_cycle'. If the form is submitted after January 15th, it should have the value 'Spring, [year]', or if after July 15th, it should be ...

Try uploading a file with the imageUpload function in JavaScript, could be something basic

Today I successfully uploaded a picture using a basic button (id: "imageUpload") to select and upload a file. Everything worked flawlessly, with the thumbnail of the picture appearing in "thumb1." Now, I am attempting to allow users to upload a picture by ...

Creating a Border Length Animation Effect for Button Hover in Material-UI

I'm currently exploring Material-UI and trying to customize a component. My goal is to add a 'Border Length Animation' effect when hovering over the button. Unfortunately, I have yet to successfully implement this animation as intended. For ...

Angular 6 CSS spacing dilemmas

We recently made the switch from Angular 5 to Angular 6 and noticed that there is no spacing between the buttons/icons, etc. We are looking to bring back the spaces between the buttons and icons. I have recreated the issue below. As you can see in the Ang ...

Handling a JSON payload within an ASP.NET MVC controller

When using jQuery post to send a json-object to my asp.net server, I am receiving a string that looks like this: "'{\"refNr\":\"124460\",\"dokid\":1}'" I am struggling to find a method that can extract the data in ...

Disappearance of background image on HTML5 canvas upon mouse movement

I am looking to incorporate the ability for users to draw sketches on an image displayed on a canvas. Currently, I am utilizing the sketch.js jQuery library and have encountered the following issues: The image loads successfully onto the canvas. However, ...

What is the best way to navigate my Page while my Dialog Component is displayed?

Is there a way to enable scrolling on the background when a dialog component opens up? By default, scrolling is disabled when the dialog appears. How can we allow scrolling in the background? Here is the code snippet: import React, { useState } from &apos ...

How to maximize efficiency by utilizing a single function to handle multiple properties in Angular

I have 2 distinct variables: $scope.totalPendingDisplayed = 15; $scope.totalResolvedDisplayed = 15; Each of these variables is connected to different elements using ng-repeat (used for limitTo) When the "Load More" button is clicked (ng-click="loadMore( ...

Issue with integrating CrunchBase API and making AJAX requests using jQuery's $.getJSON method

Can someone help me figure out why my attempt to display an alert with the "name" is not working correctly? $(document).ready(function() { $.getJSON("http://api.crunchbase.com/v/1/companies/permalink?name=Google", function(data) { alert( ...

Tips for effectively making REST requests from a ReactJS + Redux application?

I'm currently working on a project using ReactJS and Redux, incorporating Express and Webpack as well. I have successfully set up an API and now need to figure out how to perform CRUD operations (GET, POST, PUT, DELETE) from the client-side. Could so ...

Issues with retrieving the output of a function nested within another function through an ajax request

I am attempting to use jQuery to add the results of an ajax call to a paragraph. My goal is to extract the "myResult" variable from the inner getResult function and transfer it to the outer buildParagraph function. Unfortunately, the returned value is und ...

Encountering a problem with AngularJS ui router templates

I have defined the following routes in my project: $stateProvider .state('access', { abstract: true, url: '/access', templateUrl: 'login.html' }) .state('access.signin', { ...

What is the method for accessing an anonymous function within a JavaScript Object?

Currently facing an issue with a Node.js package called Telegraf, which is a bot framework. The problem arises when trying to create typings for it in TypeScript. The package exports the following: module.exports = Object.assign(Telegraf, { Composer, ...

Rendering content conditionally using react technology

There is a functional component that receives two items as props. The properties can have values like `undefined`, `""`, `null`, `"null"`, or a valid string (e.g. `"test"`). The goal is to conditionally render these props based on their values. If both ` ...