javascript - How to display content depending on dropdown menue user selection -


i have dropdown menu @ bottom of form 6 different options. need display different content on div below menu depending on option selected.

no additional content should visible until user select 1 of options , once user select 1 of options content associated specific option should visible.

i need create functionality using javascript knowledge of javascript limited , don’t seem find need online.

i believe need create 6 different divs(one each option) , toggle class makes them visilble once respective title selected.

here dropdown menu have:

 <div class="field">     <label for="rolebox" data-label="i_am">{% trans %} main.i_am_title {% endtrans %}</label>     <div class="f-wrapper">        <select class="cbx" tabindex="50" name="role">               <option value="student">a student</option>               <option value="educator">an educator</option>               <option value="parent">a parent signing child</option>               <option value="not-school">not in school still learning</option>               <option value="publisher">a publisher or interested kno partner</option>        </select>     </div>  </div> 

any appreciated.

i added divs mentioned , gave each id makes javascript little easier.

javascript

var ids=["student", "educator", "parent", "not-school", "publisher"]; var dropdown = document.getelementbyid("rolesel");  dropdown.onchange = function(){     for(var x = 0; x < ids.length; x++){            document.getelementbyid(ids[x]).style.display="none";     }         document.getelementbyid(this.value).style.display = "block"; } 

html

 <div class="field">     <label for="rolebox" data-label="i_am">{% trans %} main.i_am_title {% endtrans %}</label>     <div class="f-wrapper">        <select id="rolesel" class="cbx" tabindex="50" name="role">               <option value="student">a student</option>               <option value="educator">an educator</option>               <option value="parent">a parent signing child</option>               <option value="not-school">not in school still learning</option>               <option value="publisher">a publisher or interested kno partner</option>        </select>     </div>  </div> <div id="student" class="hidden">student div</div> <div id="educator" class="hidden">educator div</div> <div id="parent" class="hidden">student div</div> <div id="not-school" class="hidden">not school div</div> <div id="publisher" class="hidden">student div</div> 

working example http://jsfiddle.net/qbzmz/


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -