0

我正在建立一个网站,该网站将根据 10 种不同的测量值来识别零件。我希望我的第一个下拉框中的 onchange 事件做两件事。首先,我需要它将我的选择发布到下一页的 php 变量中。其次,我希望该功能加载下一页,这将为我提供另一个下拉列表,该列表仅显示与第一个列表具有相同度量的选项。我基本上正在构建 10 个页面,这些页面只是不断添加到生成我的下拉列表的 sql 语句中。我只是不确定如何将 jquery 帖子发送到 php 变量,以及如何加载新页面。我是编程新手,所以我试图保持这个不太复杂。这是我的代码的基础知识。

<html>
    <head>
        <script type = "text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>    
        <script type='text/javascript'>
        function get() {
                var lengthdata = $('#filter').serialize();
                $.post('spline.php', lengthdata,
                function(output){
                        $('#list').html(output);
                        });
                }           
        </script>   
    </head>     
    <body>
        <div id="id1"></div>
        <?php
        //database login and connection.
        $dbhost = "localhost";
        $dbuser = "root";
        $dbpass = "password";
        $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die("could not connect!");
        $select_db = mysql_select_db('camdb') or die('could not select camdb database!!');
        echo "<style type='text/css'>";
        echo "td {padding: 10px;}";
        echo "</style>";
        echo "<form name='filter' id='filter'><table><tr>";

        echo"<div id='lengthsel'>";
        $query = "SELECT DISTINCT Length FROM camTable;";
        $result = mysql_query($query);

        echo"<td>Cam Length" . "<br/>";
        echo"<select name=\"Length\" id='Length' onchange='get()'>/n";
        echo"<option value=''>Select</option>";
        while ($row = mysql_fetch_array($result)) {
            echo "<option value='" . $row['Length'] . "'>" . $row['Length'] . "</option>";
        }
        echo "</select></td>";
        echo"</tr></table></form>";
        echo"</div>";
        ?>
        <div id="list"></div>
    </body>
</html>

这基本上就是其余页面的内容

<html>
    <head>
        <script type = "text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>    
        <script type='text/javascript'>
        function get() {
                var splinedata = $('#filter').serialize();
                $.post('spider.php', splinedata, 
                function(output){
                        $('#list').html(output);
                        });
                }           
        </script>   
    </head>     
    <body>
        <?php
        $dbhost = "localhost";
        $dbuser = "root";
        $dbpass = "password";
        $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die("could not connect!");

        $select_db = mysql_select_db('camdb') or die('could not select camdb database!!');

        $sql = "SELECT * FROM camtable WHERE ";
        if ($_REQUEST['Length'] != "") {
            $sql.='length="' . mysql_real_escape_string($_REQUEST['Length']) . '";';
        }

        //$sql.="ORDER BY length, spline, spider, support, head, nose, grov1";
        echo $sql . "<br/>";

        $result = mysql_query($sql);

        $sql = "SELECT * FROM camtable WHERE ";
        if ($_REQUEST['Length'] != "") {
            $sql.='length="' . mysql_real_escape_string($_REQUEST['Length']) . '";';
        }
        $result = mysql_query($sql);

        echo"<td>Spline" . "<br/>";
        echo"<select name=\"spline\"id='spline' onchange='get()'>/n";
        echo"<option value=''>Select</option>";
        while ($row = mysql_fetch_array($result)) {
            echo "<option value='" . row['spline'] . "'>" . $row['spline'] . "</option>";
        }
        echo "</select></td>";
        ?>
    </body>
</html>
4

1 回答 1

0

我想你正在寻找的是

$(document).ready(function(){
    $('select').change(function(){ $('#form1')[0].submit();});
});

假设您的选择在表单内<form id="form1" action="secondPage.php" method="post">

在第二页中,您使用$_POST['selectName']

于 2013-07-01T03:21:29.010 回答