Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript无法在复选框中获取变量_Javascript_Php_Jquery - Fatal编程技术网

javascript无法在复选框中获取变量

javascript无法在复选框中获取变量,javascript,php,jquery,Javascript,Php,Jquery,我正在尝试实现一个包含座位预订系统的电影院网页。我从这个页面获得了一些帮助,当我单独测试它时,它工作得非常好 但是,当我尝试在我的网站中实现它时,seat复选框似乎不起作用,当我按下Reserve seat按钮(我在一些框中进行了选中)时,它总是提醒“请在单击之前选择一个座位” 我使用index.php并包含我网站上的每个页面,以便在调用时加载 以下是我的index.php代码: <?php ob_start(); include ('pages/top.php');

我正在尝试实现一个包含座位预订系统的电影院网页。我从这个页面获得了一些帮助,当我单独测试它时,它工作得非常好

但是,当我尝试在我的网站中实现它时,seat复选框似乎不起作用,当我按下Reserve seat按钮(我在一些框中进行了选中)时,它总是提醒“请在单击之前选择一个座位”

我使用index.php并包含我网站上的每个页面,以便在调用时加载

以下是我的index.php代码:

 <?php 
    ob_start();
    include ('pages/top.php');
    $ui1 = $_GET['ui1'];
    if (!$ui1) { $ui1 = 'movie';}
    $ui2 = $_GET['ui2'];
    if (!$ui2) { $ui2 = 'homepage';}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
    </script>
    <title>4starCine</title>
    <meta name="description" content="4starcinema website" />
    <meta name="keywords" content="4starcinema,4starcine,4star,cine" />
    <meta name="author" content="HTTA group 4" />
    <link rel="stylesheet" href="css/style.css" type="text/css" />
    <link rel="stylesheet" href="css/style2.css" type="text/css" />
</head>
<body>
    <div class="backdrop">


        <div class="wrapper">
            <div class="header">
                <?php include ('pages/head.php')?>
            </div>

            <div class="content">
                <?php 
                if (file_exists('pages/'.$ui1.'/'.$ui2.'.php')) {
                    include ('pages/'.$ui1.'/'.$ui2.'.php');
                    }
                else {
                    include ('pages/notfound.php');
                    }
                ?>
            </div>
            <div class="clear"></div>
            <div class="footer">
                <div class="footer_mini">

                </div>
                <div class="footer_mini">
                </div>
                <div class="footer_mini">
                </div>
                <div class="footer_mini">
                </div>

            </div>

        </div>
    </div>  
</body>
</html>

4starCine
在booking.php中,它将包含在index.php中:

<?php
    session_start();
    if ($_SESSION['user']!=1){
        header("location:index.php?ui1=member&ui2=login");
    }
?>
<html>
<head>
    <title>Tickets</title>

    <script>

        function reserveSeats() {

            var selectedList = getSelectedList('Reserve Seats');

            if (selectedList) {
                if (confirm('Do you want to reserve selected seat/s ' + selectedList + '?')) {
                    document.forms[0].oldStatusCode.value=0;
                    document.forms[0].newStatusCode.value=1;
                    document.forms[0].action='bookseats.php';
                    document.forms[0].submit();
                } else {
                    clearSelection();
                }
            }
        }


        function cancelSeats() {

            var selectedList = getSelectedList('Cancel Reservation');

            if (selectedList) {
                if (confirm('Do you want to cancel reserved seat/s ' + selectedList + '?')) {
                    document.forms[0].oldStatusCode.value=1;
                    document.forms[0].newStatusCode.value=0;
                    document.forms[0].action='bookseats.php';
                    document.forms[0].submit();
                } else {
                    clearSelection();
                }
            }
        }


        function confirmSeats() {

            var selectedList = getSelectedList('Confirm Reservation');

            if (selectedList) {
                if (confirm('Do you want to confirm reserved seat/s ' + selectedList + '?')) {
                    document.forms[0].oldStatusCode.value=1;
                    document.forms[0].newStatusCode.value=2;
                    document.forms[0].action='bookseats.php';
                    document.forms[0].submit();
                } else {
                    clearSelection();
                }
            }
        }


        function getSelectedList(actionSelected) {

            // get selected list
            var obj = document.forms[0].elements;
            var selectedList = '';
            for (var i = 0; i < obj.length; i++) {
                if (obj[i].checked && obj[i].name == 'seats[]') {
                    selectedList += obj[i].value + ', ';
                }
            }

            // no selection error
            if (selectedList == '') {
                alert('Please select a seat before clicking ' + actionSelected);
                return false;
            } else {
                return selectedList;
            }

        }

        function clearSelection() {
            var obj = document.forms[0].elements;
            for (var i = 0; i < obj.length; i++) {
                if (obj[i].checked) {
                    obj[i].checked = false;
                }
            }
        }


        function refreshView() {
            clearSelection();
            document.forms[0].action='<?php echo $_SERVER['PHP_SELF']; ?>';
            document.forms[0].submit();
        }

    </script>
</head>
<body>
<table>
<tr><td width="100%" align="center">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<input type="hidden" name="oldStatusCode" value=""/>
<input type="hidden" name="newStatusCode" value=""/>

<table width='100%' border='0'>
    <tr><td align='center'>
        <input type='button' value='Refresh View' onclick='refreshView();'/>
    </td></tr>
</table>
</td></tr>
<tr><td width="100%" align="center">
<table width='100%' border='0'>
    <tr><td align='center'>
        <input type='button' value='Reserve Seats' onclick='reserveSeats()'/>
        &nbsp;<input type='button' value='Confirm Reservation' onclick='confirmSeats()'/>
        &nbsp;<input type='button' value='Cancel Reservation' onclick='cancelSeats()'/>
    </td></tr>
</table>
</td></tr>
<tr><td width="100%" align="center">
<table width='100%' border='0'>
    <tr><td align='center'>
        <input type='button' value='Clear Selection' onclick='clearSelection()'/></td>
    </tr>
</table>
</td></tr>
<tr><td width="100%" align="center">
<?php


$linkID = @ mysql_connect('localhost','huyhd','hdh8623') or die("Could not connect to MySQL server");
@ mysql_select_db("huyhd_4starcine") or die("Could not select database");
/* Create and execute query. */
$query = "SELECT * from seats order by rowId, columnId desc";
$result = mysql_query($query);
$prevRowId = null;
$seatColor = null;
$tableRow = false;
//echo $result;
echo "<table width='100%' border='0' cellpadding='3' cellspacing='3'>";
while (list($rowId, $columnId, $status, $updatedby) = mysql_fetch_row($result))
{
    if ($prevRowId != $rowId) {
        if ($rowId != 'A') {
            echo "</tr></table></td>";
            echo "\n</tr>";
        }
        $prevRowId = $rowId;
        echo "\n<tr><td align='center'><table border='1' cellpadding='8' cellspacing='8'><tr>";
    } else {
        $tableRow = false;
    }
    if ($status == 0) {
        $seatColor = "lightgreen";
    } else if ($status == 1 && $updatedby == 'user1') {
        $seatColor = "FFCC99";
    } else if ($status == 1 && $updatedby == 'user2') {
        $seatColor = "FFCCFF";
    } else if ($status == 2 && $updatedby == 'user1') {
        $seatColor = "FF9999";
    } else if ($status == 2 && $updatedby == 'user2') {
        $seatColor = "CC66FF";
    } else {
        $seatColor = "red";
    }

    echo "\n<td bgcolor='$seatColor' align='center'>";
    echo "$rowId$columnId";
    if ($status == 0 || ($status == 1 && $updatedby == $_SESSSION['username'])) {
        echo "<input type='checkbox' name='seats[]' value='$rowId$columnId'></checkbox>";
    }
    echo "</td>";
        if (($rowId == 'A' && $columnId == 7) 
            || ($rowId == 'B' && $columnId == 9) 
            || ($rowId == 'C' && $columnId == 9) 
            || ($rowId == 'D' && $columnId == 10) 
            || ($rowId == 'E' && $columnId == 8) 
            || ($rowId == 'F' && $columnId == 5) 
            || ($rowId == 'G' && $columnId == 13) 
            || ($rowId == 'H' && $columnId == 14) 
            || ($rowId == 'I' && $columnId == 14) 
            || ($rowId == 'J' && $columnId == 12) 
            || ($rowId == 'K' && $columnId == 14) 
            || ($rowId == 'L' && $columnId == 13) 
            || ($rowId == 'M' && $columnId == 9)) {
            // This fragment is for adding a blank cell which represent the "center aisle"
            echo "<td>&nbsp;</td>";
        }
}

echo "</tr></table></td>";
echo "</tr>";
echo "</table>";

/* Close connection to database server. */
mysql_close();
?>
</td></tr>
<tr><td>&nbsp;</td></tr>
<tr><td width="100%" align="center">
    <table border="1" cellspacing="8" cellpadding="8">
        <tr>
            <td bgcolor='lightgreen'>Available</td>
            <td bgcolor='FFCC99'>Reserved user1</td>
            <td bgcolor='FF9999'>Confirmed user1</td>

        </tr>
    </table>
</td></tr>
<tr><td>&nbsp;</td></tr>

</table>
</form>
</body>
</html>

售票处
功能预留座位(){
var selectedList=getSelectedList(“预留座位”);
如果(已选择列表){
如果(确认(‘您想预订选定的座位吗?’+selectedList+’?)){
document.forms[0].oldStatusCode.value=0;
document.forms[0].newStatusCode.value=1;
document.forms[0]。action='bookseats.php';
document.forms[0]。提交();
}否则{
选举();
}
}
}
功能取消座位(){
var selectedList=getSelectedList(“取消预订”);
如果(已选择列表){
如果(确认(‘您想取消预订座位吗?’+selectedList+’?)){
document.forms[0].oldStatusCode.value=1;
document.forms[0].newStatusCode.value=0;
document.forms[0]。action='bookseats.php';
document.forms[0]。提交();
}否则{
选举();
}
}
}
函数confirmSeats(){
var selectedList=getSelectedList('Confirm Reservation');
如果(已选择列表){
如果(确认('您想确认预订座位吗?'+已选座位列表+'?')){
document.forms[0].oldStatusCode.value=1;
document.forms[0].newStatusCode.value=2;
document.forms[0]。action='bookseats.php';
document.forms[0]。提交();
}否则{
选举();
}
}
}
函数getSelectedList(actionSelected){
//获取选定列表
var obj=document.forms[0]。元素;
var selectedList='';
对于(变量i=0;i
for (var i = 0; i < obj.length; i++) {
if (obj[i].name == 'seats[]') {
  $("input:checkbox[name='type']:checked").each(function()
  {

   selectedList += obj[i].value + ', ';

});

}

}
for(变量i=0;i
您的问题如下所示:

var obj = document.forms[0].elements;

包含复选框的表单不是表单0,因为您有另一个表单要搜索。应该是
forms[1]

消息在哪里
请在单击前选择一个座位。对不起,我添加了getSelectedList功能。您可以提供呈现的HTML吗?最感兴趣的是
表单
和复选框元素名称。在您的测试页面中预订座位的登录凭据(用户名和密码)是什么?@user2986673最好给您的表单一个
id
,并通过该
id
访问它。好主意。非常感谢,你是我的救世主