Jump to content

hide/show divs.. how do i do that?


jwk811

Recommended Posts

i want to have a form that has two options using radio buttons and depending on which ever they pick a set of new options would show up.. i was told that this could be done by hiding and showing <div>s but im not sure how i can do that.. so if anyone could please show me how that would be great
Link to comment
Share on other sites

You will need to do someting like this..

Javascript

[code]
function showHideDiv() {
    var div = document.getElementById('yourDiv').style;
    if (div.visibility == 'visible') {
div.visibility = 'hidden';
    } else {
div.visibility = 'visible';
    }
}[/code]

Now you will have to define the visibility state in the div it's self for this to work..

Like this.

[code]<div id="yourDiv" style="visibility:hidden;">Something here</div><a href="#" onclick="showHideDiv();">Click to show/hide the div</a>[/code]

You can also use display..

Like this.

[code]
function showHideDiv() {
    var div = document.getElementById('yourDiv').style;
    if (div.display == 'block') {
div.display = 'none';
    } else {
        div.display = 'block';
    }
}[/code]

Hope that helps,
Tom
Link to comment
Share on other sites

how can i set that up using radio buttons. the code above would work with check boxes but now im stuck playing around with the code to get it to work for the buttons. can you see what my problem would be? if there was like an offclick thing when the button goes to a different one it would work
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.