简体   繁体   中英

hiding and showing dropdowns using javascript

I am in a very confused state how to write this code. Actually my requirement is .. I have a 5 drop down boxes in which first one should be constant and others should remain hidden. Based on the option selected in the first drop down box i need to display other drop downs. But here comes the tricky part... If for example.. i have selected "java" option in main drop down box java drop down box should appear , if again i select another option along with java box another drop down box should also appear.

<!DOCTYPE html><body>
<select name="select"  value="select" id="skill" onchange="check(this[this.selectedIndex].value)">
<option value="select"><b>select<b>
<option id="vjava" value="java"><b>java<b>
<option value="dotnet"><b>dotnet<b>
<option value="oracle"><b>oracle<b>
<option value="MSBI"><b>msbi<b>
<option value="powerbuilder"><b>powerbuilder<b>
</select>
<br>
<br>
<span id="javan"><b>java<b></span><select id="java">
<option value="beginner"><b>Beginner<b>
<option value="intermediate"><b>Intermediate<b>
<option value="expert"><b>Expert<b>
</select>
<br>
<br>
<span id="dotnetn"><b>.Net<b></span><select id="dotnet">
<option value="beginner"><b>Beginner<b>
<option value="intermediate"><b>Intermediate<b>
<option value="expert"><b>Expert<b>
</select>
<br>
<br>
<span id="oraclen">Oracle</span><select id="oracle">
<option value="beginner">Beginner
<option value="intermediate">Intermediate
<option value="expert">Expert
</select>
<br>
<br>
<span id="msbin">Msbi</span><select id="msbi">
<option value="beginner"><b>Beginner
<option value="intermediate"><b>Intermediate<b>
<option value="expert"><b>Expert<b>
</select>
<br>
<br>
<span id="powerbuildern"><b>Powerbuilder<b></span><select id="powerbuilder">
<option value="beginner"><b>Beginner<b>
<option value="intermediate"><b>Intermediate<b>
<option value="expert"><b>Expert<b>
</select>
</body></html>                           

Try this using Jquery

 $("#main").on("change", function() { if ($("#main").val() == "Java") { $("#Java").removeClass("h"); $("#Java").addClass("s"); } if ($("#main").val() == ".net") { $("#Net").removeClass("h"); $("#Net").addClass("s"); } if ($("#main").val() == "C#") { $("#C").removeClass("h"); $("#C").addClass("s"); } }) 
 .h { display: none; } .s { dsplay: block; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <select multiple id="main"> <option>Java <option> <option>.net <option> <option>C# <option> </select> <select id="Java" class="h"> <option>Java</option> </select> <select id="Net" class="h"> <option>.Net</option> </select> <select id="C" class="h"> <option>C#</option> </select> 

Let me know if that what u are asking

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM