SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 :

    HTML Code:
    <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.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    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
    1. gets a class name from the selected option
    2. shows or hides the div depending on that class name


    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •