JavaScript - 如何从函数传递/存储值以形成隐藏字段?

时间:2016-09-04 17:25:51

标签: javascript php jquery html forms

请问,我在下面的JavaScript中遇到问题。我不习惯JavaScript ...我在下面的是一个票务预订脚本,显示所选票证的数量,总金额和座位行/座位号。我想选择机票,座位排,座位号码(所有选定的座位e,g 3,5和8,2表示第3排座位5和第8排座位2)和HTML表格中的数量HIDDEN FIELD as显示在代码中的某个位置,然后通过提交按钮将这些值发送到另一个页面,然后通过PHP获取它们。

<div class="booking-details">
  <ul class="book-left">
    <li>Time </li>
    <li>Tickets</li>
    <li>Total</li>
    <li>Seats :</li>
 </ul>
 <ul class="book-right">        
    <li>: April 3, 21:00</li>
    <li>: <span id="counter">0</span></li>
    <li>: <b><i>$</i><span id="total">0</span></b></li>
 </ul>
 <div class="clear"></div>
 <ul id="selected-seats" class="scrollbar scrollbar1"></ul>


 <!-- HTML FORM WHERE HIDDEN INPUT IS LOCATED TO GET THE VARIABLES -->
                                                             
            <div id="legend"></div>
        </div>
        <div style="clear:both"></div>
    </div>

        <script type="text/javascript">
            var price = 52; //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',
                        '__________',
                        'aaaaaaaa__',
                        'aaaaaaaaaa',
                        'aaaaaaaaaa',
                        'aaaaaaaaaa',
                        'aaaaaaaaaa',
                        'aaaaaaaaaa',
                        '__aaaaaa__'
                    ],
                    naming : {
                        top : false,
                        getLabel : function (character, row, column) {
                            return column;
                        }
                    },
                    legend : { //Definition legend
                        node : $('#legend'),
                        items : [
                            [ 'a', 'available',   'Available' ],
                            [ 'a', 'unavailable', 'Sold'],
                            [ 'a', 'selected', 'Selected']
                        ]                   
                    },
                    click: function () { //Click event
                        if (this.status() == 'available') { //optional seat
                            $('<li>Row'+(this.settings.row+1)+' Seat'+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(['', '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>
</div>

1 个答案:

答案 0 :(得分:0)

如果必须将值传递给隐藏输入,可以设置如下值:

$("#price").val(total);