Drop-down box dependent on the option selected in another drop-down box

后端 未结 7 1761
半阙折子戏
半阙折子戏 2020-11-29 05:55

I have 2 different SELECT OPTION in a form.

The first one is Source, the second one is Status. I would like to have different OPTIONS in my Status drop-down list dep

相关标签:
7条回答
  • 2020-11-29 06:56

    In this jsfiddle you'll find a solution I deviced. The idea is to have a selector pair in html and use (plain) javascript to filter the options in the dependent selector, based on the selected option of the first. For example:

    <select id="continents">
     <option value = 0>All</option>   
     <option value = 1>Asia</option>
     <option value = 2>Europe</option>
     <option value = 3>Africa</option>
    </select> 
    <select id="selectcountries"></select>
    

    Uses (in the jsFiddle)

     MAIN.createRelatedSelector
         ( document.querySelector('#continents')           // from select element
          ,document.querySelector('#selectcountries')      // to select element
          ,{                                               // values object 
            Asia: ['China','Japan','North Korea',
                   'South Korea','India','Malaysia',
                   'Uzbekistan'],
            Europe: ['France','Belgium','Spain','Netherlands','Sweden','Germany'],
            Africa: ['Mali','Namibia','Botswana','Zimbabwe','Burkina Faso','Burundi']
          }
          ,function(a,b){return a>b ? 1 : a<b ? -1 : 0;}   // sort method
     );
    
    0 讨论(0)
提交回复
热议问题