SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    show/hide div based on radio button select

    hey i'm new to using Javascript and am really struggling!!!

    i would like to have 2 radio buttons each with a associated div

    when the page loads the first radio button will be checked and its corresponding div will be show

    when the user checks the other radio button its corresponding div is shown and the first div is hidden

    could anyone help with this?? or point me in the right direction

    thanks!

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    worked it out. here's my solution if anyone's interested:

    function show_hide(show, hide)
    {
    document.getElementById(show).style.display="block";
    document.getElementById(hide).style.display="none";
    }

    <form method="post" action="aaa.php">
    <input type="radio" name="search" value="standard" onClick="show_hide('standard', 'advanced')" checked />Standard Search
    <div id="standard" style="display: block;">
    Standard search div
    </div>
    <br />
    <input type="radio" name="search" value="advanced" onClick="show_hide('advanced', 'standard')" />Advanced search
    <div id="advanced" style="display: none;">
    Advanced search div
    </div>
    <br />
    <input type="submit" value="Submit" />
    </form>

  3. #3
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    good idea, but one question on that.
    How do i make a 3rd Div and a third checkbox. ?

    I added
    function show_hide(show, hide, hide)

    and a third
    document.getElementById(hide).style.display="none";

    and a new

    onClick="show_hide('advanced', 'standard', 'newone')"

    on the radio butttons but that dont work !

    Any advise ?

    best regards
    Stefan


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
  •