Toggle onchange Select box to show hidden DIV

hi all

i’m new here and i want to ask about javascript

i have a select box, when user select value other than ‘H’ then the hidden <DIV> element will showed up, and when user select value ‘H’ the <DIV> element will hide again

the code is like this :


<select name="show_status">
<option value="H">Is Hidden</option>
<option value="S">Show me the DIV</option>
<option value="X">Show me the DIV (again)</option>
</select>

<div id="MyContent" style="display: none">
Name : <br />
<input type="text" name="name" size="20" />
</div>

if user select ‘S’, then the DIV element will showed up

if user select ‘X’, then the DIV element also still showed up

and if user select ‘H’, then the DIV element will be hide again

Any suggestions or help would be great.
thank you.
:slight_smile:

The steps you’ll want to take are:

[list=1][]attach an onchange event to the select element
[
]when the page is loaded, trigger that onchange event[list]

The onchange event does two things

[list=1][]gets a class name from the selected option
[
]shows or hides the div depending on that class name
[/list]

If you want someone to write this code for you, we have a Marketplace where peoples services can be hired.

If instead you’re here to learn, we can help you there too.