0

I am working on a website to make reservations. I have this function in javascript to create the view to choose the seat.

When loading the page you get the seats that are already occupied with PHP. (They are saved in a database). But I do not know how to call the function again.

I thought of creating everything from php but I can not figure out how to embed a variable in an html element already created.

 var init = function (reservedSeat) {
            var str = [], seatNo, className;
            for (i = 0; i < settings.rows; i++) {
                for (j = 0; j < settings.cols; j++) {
                    seatNo = (i + j * settings.rows + 1);
                    className = settings.seatCss + ' ' + settings.rowCssPrefix + i.toString() + ' ' + settings.colCssPrefix + j.toString();
                    if ($.isArray(reservedSeat) && $.inArray(seatNo, reservedSeat) != -1) {
                        className += ' ' + settings.selectedSeatCss;
                    }
                    str.push('<li class="' + className + '"' +
                                  'style="top:' + (i * settings.seatHeight).toString() + 'px;left:' + (j * settings.seatWidth).toString() + 'px">' +
                                  '<a title="' + seatNo + '">' + seatNo + '</a>' +
                                  '</li>');
                }
            }
            $('#place').html(str.join(''));

        };

        var bookedSeats = [5, 10, 25];
init(bookedSeats);
  • you can't access client javascript after PHP has processed a page on the server and sent it to the client – Jaromanda X Nov 21 '16 at 01:44
  • 4
    You have 2 options: 1- use `ajax` from you JavaScript upon page load and get the data from server and then call your JavaScript function. 2- in your php code create a string in the `JavaScript object` format or in `json` format and then echo it like this `echo '';` in your html, then again upon page load in javascript read the content of this variable and do what you want to do with it. – EhsanT Nov 21 '16 at 01:48

0 Answers0