Jump to content

JS Switch Content


centenial

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?
Link to comment
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,
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.