Jump to content

Archived

This topic is now archived and is closed to further replies.

centenial

JS Switch Content

Recommended Posts

Hi,

I've been driving myself crazy the past couple hours and can't figure this out. Here is what I need to do:

Have a select box like this:

[code]<select name="dropdown">
<option value="option1">option1</option>
<option value="option2">option2</option>
</select>[/code]

Then when one of those options is selected, the appropriate div tag is displayed:

[code]<div id="option1">
Div 1 Text
</div>

<div id="option2">
Div 2 Text
</div>[/code]

This seems like it should be really simple to do, but I can't figure it out. Please help someone?

Share this post


Link to post
Share on other sites
Try this
[code]
<script language="javascript">
    function hide(){
        document.getElementById('option1').style.display = "none";
        document.getElementById('option2').style.display = "none";
    }
    function show(wdiv){
        hide();
        document.getElementById(wdiv).style.display = '';
    }
</script>

<select name="dropdown" onChange="show(this.value);">
<option value="option1">option1</option>
<option value="option2">option2</option>
</select>

<div id="option1" style="display:none;">
Div 1 Text
</div>

<div id="option2" style="display:none;">
Div 2 Text
</div>
[/code]

Make sure you include all the divs to the hide function,

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.