DropDown菜单更改OnChange [英] DropDown Menu Changing OnChange

查看:527
本文介绍了DropDown菜单更改OnChange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个下拉菜单。所有3个都相互关联。即,如果我选择第一个下拉列表的值,则取决于第二个下拉列表应显示的值。取决于第二个下拉列表的选择,第三个下拉列表应填充值。已经完成了第一和第二。但根据第二个下拉列表的值不能填充第三个下拉列表的值。任何人都可以帮助我。我知道这样的事情将在JFIDDLE.com。但无法精确确定搜索名称!

I have 3 dropdown menu. and all 3 are interlinked. ie, if i select the values of 1st dropdown, depending on that the second dropdown should display values. depending on the selection of 2nd dropdown, 3rd dropdown should populate the values. have done for 1st and 2nd. but depending on the values of 2nd drop down am not able to populate the values of 3rd dropdown. can anyone plaz help me. i know something like this will be in JFIDDLE.com. but not able to fine the exact name to search that!

推荐答案

如果需要,您必须使用AJAX。

You have to use AJAX if you want that. it will be easy.

<select name="ID"
                    id="ID"
                    onchange="DoYourTaskHere(this);">
                        <option value="select" selected="selected">Select</option>
                        <c:forEach items="${A.List}" var="Variable">
                            <option value="${ID}">
                                <c:out value="${ID}" />
                            </option>
                        </c:forEach>
                </select>

并在脚本中编写代码如下。

And in the script you write the code as follows.

function loadValue(ID) {
    if (ID.value != "select") {
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera,
                                    // Safari
            ValueXmlHttpReq = new XMLHttpRequest();
        } else {// code for IE6, IE5
            ValueXmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
        ValueXmlHttpReq.onreadystatechange = processLoadValues;
        ValueXmlHttpReq.open("POST", "getValue.htm?ID="
                + ID.value, true);
        ValueXmlHttpReq.send();
    } else {
        var objSelect = document.getElementById("ValueId");
        var currentValueListLength = objSelect.options.length;
        while (currentValueListLength > 0) {
            objSelect.remove(1);
            currentValueListLength--;
        }

        var objSelect = document.getElementById("2ndDropDownWhereYouWantToPopulate");
        var currentSecondValueListLength = objSelect.options.length;
        while (currentSecondValueListLength > 0) {
            objSelect.remove(1);
            currentSecondValueListLength--;
        }
    }
}

这篇关于DropDown菜单更改OnChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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