×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

Several ways

1) submit the page and refresh the list content of the second dropdown box use server side tech. (asp/jsp/isapi/cgi......)
2) build the tree into javascript, in onchange event of the first dropdown box, using DOM/script to modify the items of the second one. If the number of items are not too much, this is the fastest way.
3) In onchange event of the first dropdown box, generate a xmlhttprequest object and fill in the value, and on the server side, return the list, then using DOM/script to modify the list in dropdown box B. This one require MSXML on the client side, good for intranet applications.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / html代码问题
    html里面的drop-down box人家可以做出的效果是,

    改变一个drop-down box的内容,另外一个drop-down box里面的内容会自动去数据库更新,这个是form里面的什么属性触发的?

    谢谢
    • 随便找个网页看看source就知道了,有个event专门是select 改变后就变的,Sun主页上原来有个technology list ,选中一个就把你navigate到别的页
    • javascript, onchange
    • 我认为用静态html代码不可能实现。如果用动态网页,比如ASP.NET,非常容易。
    • ?????用php能写吗???????
      最好能给个很简单的代码,谢谢
    • selectedindexchanged
      • 哪种语言?
    • Several ways
      1) submit the page and refresh the list content of the second dropdown box use server side tech. (asp/jsp/isapi/cgi......)
      2) build the tree into javascript, in onchange event of the first dropdown box, using DOM/script to modify the items of the second one. If the number of items are not too much, this is the fastest way.
      3) In onchange event of the first dropdown box, generate a xmlhttprequest object and fill in the value, and on the server side, return the list, then using DOM/script to modify the list in dropdown box B. This one require MSXML on the client side, good for intranet applications.
      • #1559923?thx
        • I have samples for both 1) and 2) in my project, will post tomorrow after get to office. The third one is in my new project, no sample yet.
          • sorry, but I meant if it's possible in perl?
            • Sorry I am not a perl/php guy. I am using ISAPI/DHTML/Javascript in my projects.
              • : )
                It's OK.
                • html code should like this:
                  <select id="box1" onchange="getyour2ndbox()">
                  <option>item1</option>
                  ..
                  ..
                  </select>

                  then in this 'get...()' to fill your other dropdown box data.
            • Here comes the code for #2
              本文发表在 rolia.net 枫下论坛<code>

              <html>

              <head>
              <title>Test Dynamic Dropdown box</title>
              <script language=javascript>
              function getSelectedIndex(aSelector) {
              for(var i = 0; i<aSelector.options.length;i++)
              if (aSelector.options[i].selected)
              return i;
              return -1;
              }
              function clearOptions( aSelector ) {
              while ( aSelector.length != 0 )
              aSelector.options.remove(0);
              }
              function appendOption( aSelector, aOption ) {
              for( var i = 0; i < aSelector.options.length; i++) {
              if (aSelector.options[i].text == aOption) return;
              }
              var aItem = document.createElement("OPTION");
              aItem.text = aOption;
              aSelector.options.add(aItem);
              }
              function resetOptions( aSelector, aList ) {
              clearOptions(aSelector);
              aList.sort();
              for( var i = 0; i<aList.length; i++)
              appendOption(aSelector,aList[i]);
              }
              var Select2Options = new Array(
              new Array("Option11","Option12"),
              new Array("Option21","Option22")
              );
              function AdjustOptions() {
              var n = getSelectedIndex(document.all.select1);
              if ( n >= 0 ) {
              resetOptions(document.all.select2,Select2Options[n]);
              }
              }
              </script>
              </head>

              <body>
              <form>
              <select name="select1" onchange="javascript:AdjustOptions()">
              <option selected>Option1</option>
              <option>Option2</option>
              </select>
              <select name="select2">
              </select>
              <script language=javascript>
              document.all.select1.onchange();
              // For the initial load
              </script>
              </form>

              </body>

              </html>





              </code>更多精彩文章及讨论,请光临枫下论坛 rolia.net
        • The code for #3 is very similar, except the list comes from an xmlhttprequest.respondtext, and require a server side module to return the list.