troubleshooting Question

show/hide div using select option

Avatar of mvanthof
mvanthof asked on
JavaScript
4 Comments1 Solution1367 ViewsLast Modified:
Hello,

this code below is working but, I like to change the value so it match the div id.

some thing like:

<option value="Kies">Choose</option>
div id is than also "Kies"
<div id="Kies" style="display:none">Gratis Artikel test div</div>

<script type='text/javascript'>
 
function toggleSubmit(obj){
 
count=0
while(document.getElementById("d"+count)){
document.getElementById("d"+count).style.display="none"
count++
}
document.getElementById("d"+obj.selectedIndex).style.display="block"
 
}
</script>
 
<SELECT id="ptype" NAME="ptype" onchange="toggleSubmit(this)">
<option value="Kies">Choose</option>
<option value="Gratis Artikel">Gratis Artikel</option>
<option value="Tell a Friend">Tell a Friend</option>
</select>
 
<div id="d0" style="display:none">choose test div</div>
<div id="d1" style="display:none">Gratis Artikel test div</div>
<div id="d2" style="display:none">Tell a Friend test div</div>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros