Php 如何通过单击将一个listbox值传递给其他listbox

Php 如何通过单击将一个listbox值传递给其他listbox,php,javascript,html,mysql,listbox,Php,Javascript,Html,Mysql,Listbox,我正在使用php和mysql构建一个在线商店应用程序。我制作了一个列表框,可以用来列出主要类别。。一旦我们选择了主要类别,子类别就应该下来了。没有按下按钮或重新加载页面,我们如何完成这项任务 列表框的代码 <select name="category" id="inputarealistproduct" onfocus="getsubcat();"> <option> Select category</option> <?php

我正在使用php和mysql构建一个在线商店应用程序。我制作了一个列表框,可以用来列出主要类别。。一旦我们选择了主要类别,子类别就应该下来了。没有按下按钮或重新加载页面,我们如何完成这项任务

列表框的代码

<select name="category" id="inputarealistproduct" onfocus="getsubcat();">
        <option> Select category</option>
    <?php 
        $query="select id, categories_name from categories where parent_id=0";
        $result=mysql_query($query);
        while(list($id, $name)=mysql_fetch_row($result)) 
        {
            echo "<option value=\"".$id."\">".$name."</option>";            
        }
    ?></select>

选择类别
桌子的设计是

id类别\u名称父项\u id类别\u排序

请帮帮我


谢谢

试试这个:Jquery+Ajax

 $('#inputarealistproduct').change(function () {
      var product =  $('#inputarealistproduct').val();
       $.ajax({
            url : 'url of your page where you ececute query',
            type : 'GET',
            data : {
                item : product
            },
            success : function (resp) {
                if (resp.status) {
                    // manipulate your response data here.
                } else {
                    show_message('error', resp.msg);
                }
            }
        });

    })

我建议您在第一个列表框上实现onchange事件,以便用该类别的子类别填充另一个列表框:

<select name="category" id="inputarealistproduct" onfocus="getsubcat();" onchange="GetSubCategories()">
        <option> Select category</option>
    <?php 
        $query="select id, categories_name from categories where parent_id=0";
        $result=mysql_query($query);
        while(list($id, $name)=mysql_fetch_row($result)) 
        {
            echo "<option value=\"".$id."\">".$name."</option>";            
        }
    ?></select>
<div id="result"></result>
in process.php:

<?php
$category = $_GET["category"];
// change the query so that the column names match your subcategory table
$query="select id, sub_categories_name from subcategories where category_id=". $category;
$result=mysql_query($query);
?>

<select name="subcategory" id="subcategory">
            <option>Select sub category</option>
        <?php while(list($id, $name)=mysql_fetch_row($result)) 
            {
                echo "<option value=\"".$id."\">".$name."</option>";            
            }
        ?>
</select>

选择子类别

这是第一个列表框吗?是的,它是主要类别的列表框。亲爱的娜达·内奥希,代码对我不适用。。我没有获得所选索引的值,这意味着类别的获取值我已经编辑了我的文章,现在类别id是通过以下方法获得的:var categoryId=document.getElementById(“InputRealityProduct”).value;
<?php
$category = $_GET["category"];
// change the query so that the column names match your subcategory table
$query="select id, sub_categories_name from subcategories where category_id=". $category;
$result=mysql_query($query);
?>

<select name="subcategory" id="subcategory">
            <option>Select sub category</option>
        <?php while(list($id, $name)=mysql_fetch_row($result)) 
            {
                echo "<option value=\"".$id."\">".$name."</option>";            
            }
        ?>
</select>