开发者

How to add more options in Javascript dependent options?

I want to add more dropdown options in this file:

http://parseven.com/java_ex.html

Now it has two and I want to make three more. Third option must be dependent on second option and so on. Please advise me. T开发者_如何学JAVAhanks in advance.


Where is the data coming from? I'm not sure which part of the answer you need most:

  1. You need to add an event handler to the OnChange event of the first dropdown.
  2. In the event handler, you need to get the data from somewhere (AJAX?)
  3. Then you need to take the new data and add it to the second dropdown.

Here is basically what you do:

document.getElementById('dropdown1').onchange = yourFunction;

function yourFunction() {
    //Here is where you need to get the data

    //Then you need to add them to the other dropdown like this:
    var dropdown2 = document.getElementById('dropdown2');

    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    dropdown2.options.add(optn);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜