【问题标题】:php page that opens based on checkboxes checked根据选中的复选框打开的 php 页面
【发布时间】:2016-10-28 03:55:27
【问题描述】:

我创建了一个包含 5 个选项的下拉菜单。同一页面上也有 6 个复选框以及一个 NEXT 按钮(输入类型)。单击下拉菜单的第一个选项启用前三个复选框,第二个选项启用后三个(禁用前三个)复选框。现在我想为不同的下拉选项打开不同的 php 页面。 让我总结一下,就像我从下拉菜单中选择选项 1,然后从复选框中选中选项 3 一样,当我单击下一个仅针对下拉菜单中的选项 1 的页面时,应该打开。下拉菜单中有 5 个选项有 5 个不同的页面。所以它应该与下拉列表链接,并且选中的复选框应该进入数据库。

这里是代码

    <select id="Objective" form="theForm" name="category" >
            <option value="0" selected="1">Choose from dropdown</option>
        <option value="bet">beta</option>
        <option value="theth">thetha</option>
        <option value="p">pi</option>
        <option value="ps">psi </option>
        <option value="alph">alpha</option>
    </select>

<input type="checkbox" class="dissable" onclick="check();" value="1" /> Laptops
<input type="checkbox" class="dissable" onclick="check();" value="1" /> Computers 
<input type="checkbox" class="dissable" onclick="check();" value="2" /> Art 
<input type="checkbox" class="dissable" onclick="check();" value="1" /> Computers Peri
<input type="checkbox" class="dissable" onclick="check();" value="1" /> Movies
<input type="checkbox" class="dissable" onclick="check();" value="2"/> Beauty 

<script>
$("#Objective").on("change", function () {
    $(".dissable[value='1']").prop("disabled", false);
    $(".dissable[value='2']").prop("disabled", false);
    if ($(this).val() == "theth") {
        $(".dissable[value='1']").prop("disabled", true);
    } else if ($(this).val() == "bet") {
        $(".dissable[value='2']").prop("disabled", true);
    } else {
        $(".dissable[value='1']").prop("disabled", true);
        $(".dissable[value='2']").prop("disabled", true);

    }
}).trigger('change');

<input type='submit' name='submit' value='Next' align='right'/>

我想我已经把我的问题说清楚了,如果仍有疑问,请询问..

【问题讨论】:

    标签: javascript jquery html checkbox


    【解决方案1】:

    嗯,可能是转录错误,但似乎缺少结束脚本标记。此外,为了将其提交到您的 php 文件,请确保具有具有所需操作的表单标签。

    <form id="myform" action="yourphpfile.php" method="post">
    <select id="Objective" form="theForm" name="category" >
        <option value="0" selected="1">Choose from dropdown</option>
        <option value="bet">beta</option>
        <option value="theth">thetha</option>
        <option value="p">pi</option>
        <option value="ps">psi </option>
        <option value="alph">alpha</option>
    </select>
    
    <input type="checkbox" class="dissable" onclick="check();" value="1" /> Laptops
    <input type="checkbox" class="dissable" onclick="check();" value="1" /> Computers
    <input type="checkbox" class="dissable" onclick="check();" value="2" /> Art
    <input type="checkbox" class="dissable" onclick="check();" value="1" /> Computers Peri
    <input type="checkbox" class="dissable" onclick="check();" value="1" /> Movies
    <input type="checkbox" class="dissable" onclick="check();" value="2"/> Beauty
    
    <input type='submit' name='submit' value='Next' align='right'/>
    </form>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script>
    $("#Objective").on("change", function () {
        $(".dissable[value='1']").prop("disabled", false);
        $(".dissable[value='2']").prop("disabled", false);
        if ($(this).val() == "theth") {
    
            // update form action for theth
            $("#myform").attr('action', 'theth.php');
    
            $(".dissable[value='1']").prop("disabled", true);
        } else if ($(this).val() == "bet") {
    
            // update form action for bet
            $("#myform").attr('action', 'bet.php');
    
            $(".dissable[value='2']").prop("disabled", true);
        } else {
    
            // assuming default means no change to form action
    
            $(".dissable[value='1']").prop("disabled", true);
            $(".dissable[value='2']").prop("disabled", true);
        }
    });
    function check() {
      // what is this supposed to do?
    }
    </script>
    

    我也不确定函数 check() 应该做什么。

    【讨论】:

    • 对于下拉菜单中的每个选项,都必须打开一个不同的页面,而不仅仅是一个页面“yourprofile.php”。所以我认为表单操作在这里不起作用。
    • 我已经关闭了脚本标签只是忘了写在这里:)
    • 在您的对象更改函数中更新操作,如
    • 请您详细说明
    • 当然,我已经用一个示例更新了代码,假设您的 php 文件与 slug 值匹配,尽管它们当然不必如此。这有帮助吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多