Jump to content


Photo

JS Switch Content


  • Please log in to reply
1 reply to this topic

#1 centenial

centenial
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 27 May 2006 - 02:13 AM

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:

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

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

<div id="option1">
Div 1 Text
</div>

<div id="option2">
Div 2 Text
</div>

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

#2 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 30 May 2006 - 06:35 PM

Try this
<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>

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

NoGray.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users