在上一个下拉列表中选择某个选项后,将其删除 [英] Remove an option once it is selected in previous dropdowns

查看:88
本文介绍了在上一个下拉列表中选择某个选项后,将其删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除上一个下拉菜单中选择的下拉菜单中的所选选项. 例如,第一个,第二个和第三个下拉列表包含A,B,C,D.一旦我在dropdown1中选择了A,它就不会同时出现在两个下拉列表2和3中. strong>

I need to remove the selected option in a dropdown that was selected on the previous dropdwon. For example the first, second and third dropdown contain A, B, C, D. Once I selected A in dropdown1, it won't appear in both dropdowns 2 and 3. Same thing will happen to both dropdowns 2 and 3.

但是在我的代码中,事情实际上是这样的:

But in my code, things are actually like this:

我在PHP中通过循环填充了几个下拉列表.

I have several dropdowns populated via loop in PHP.

for($y=1; $y<=5; $y++){
echo "<select id='seatplan$x' name='selectSeatplan[]' onChange='callSave($x,$sid)'>";

     echo "<select name='selectSeatplan[]'>";
     echo "<option value=''> ------------ </option>";
          seatplanDdNames($sid);
     echo "</select>";

} //END FOR Y<-5

请注意 * seatplanDdNames($ sid)-是一个从数据库生成名称的函数,这是我从中回显选项的方式:

Please note that * seatplanDdNames($sid) - is a function where names are generated from database and here is how i echo the options from it:

function seatplanDdNames($sid) {
     echo "<option value='$studentno' onClick='callSave($x,$sid)'>$name</option>";
}

然后将javascript函数调用Save:

Then the javascript function callSave:

function callSave(x,sid){

    var name = 'seatplan' + x;
    name = name.toString();
    var selectBox = document.getElementById(name);
    var strUser = selectBox.options[selectBox.selectedIndex].value;
    var js = document.createElement('script');
        js.setAttribute('language', 'javascript');
        js.setAttribute('type', 'text/javascript');
        js.setAttribute('src', 'seatplan-getvalues.php?uid='+strUser+'&sid='+sid+'&rtype=CLS&seatno='+x);
    document.body.appendChild(js);

    return false;
    } 

  • 函数callSave将所选选项保存在临时表中.就是我喜欢的方式.问题是,我必须避免下拉菜单中提供的数据冗余.
  • 有帮助吗?谢谢!

    推荐答案

    此处是纯HTML/JS示例.基本上在页面加载时,每个选择都有相同的选项.当您选择某项内容时,其他选择项将隐藏此选项.

    Here is pure HTML/JS example. Basically on page load each select has same options. When you select something, on other selects this option hides.

    这篇关于在上一个下拉列表中选择某个选项后,将其删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆