weixin_33719619 2015-06-24 10:14 采纳率: 0%
浏览 12

依赖下拉选择

  1. Standard selection

  2. Section Selection

  3. Subject selection

on selection depend on other section depends on standard.subject depends on section If i select subject then it display that subject assignments only

  • 写回答

1条回答 默认 最新

  • weixin_33711641 2015-06-24 11:01
    关注

    Generally, when you need something to change based on a dropdown, use the onchange event. Example:

    <select id="standardSelectId" onchange="fillSection(this)">...</select>
    <select id="sectionSelectId" onchange="fillSubject(this)"><option>-- Select Standard first --</option></select>
    <select id="subjectSelectId"><option>-- Select Section first --</option></select>
    

    Then, write a javascript function to fill the next select with options, and clear any selects that are dependent on the next select:

    <script type="text/javascript">
    function fillSection(e) {
      var choice = e.options[e.selectedIndex];
      var sectionSelect = document.getElementById("sectionSelectId");
      var subjectSelect = document.getElementById("subjectSelectId");
      subjectSelect.options.length = 0;
      try { subjectSelect.add(new Option("-- Select Section first --", ""))} catch(ex) {subjectSelect.add(new Option("-- Select Section first --", ""), null)}
      sectionSelect.options.length = 0;
      switch (choice.value) {
        case <standard val1>:
          try { sectionSelect.add(new Option(section1_label_1, section1_key_1))} catch(ex) {subjectSelect.add(new Option(section1_label_1, section1_key_1), null)}
          ...
          try { sectionSelect.add(new Option(section1_label_N, section1_key_N))} catch(ex) {subjectSelect.add(new Option(section1_label_N, section1_key_N), null)}
          break;
        case <standard valX>:
          try { sectionSelect.add(new Option(sectionX_label_1, sectionX_key_1))} catch(ex) {subjectSelect.add(new Option(sectionX_label_1, sectionX_key_1), null)}
          ...
          try { sectionSelect.add(new Option(sectionX_label_N, sectionX_key_N))} catch(ex) {subjectSelect.add(new Option(sectionX_label_N, sectionX_key_N), null)}
          break;
      }
      function fillSubject(e) {
        ...
      }
    
    评论

报告相同问题?