Jump to content

Recommended Posts

Hi.

I have 10 radiobuttons with a div under it.

<input type='radio' name='test' value='first_value' />Radio1<br/><div id="first_div">test</div>

This is what I'm trying to achieve: All div's are hidden (display:none) and if I check a radiobutton it show the div under it (display:block) and if I check other radiobutton, it will closed and open the div under the other radiobutton.

 

My attempt:

<script>
function radiobuttons(disp)
{
    for(i = 0; i < document.form1.test.length; i++){
        if(document.form1.test[i].checked){
            document.getElementById(disp).style.display = 'block';
        }else{
            document.getElementById(disp).style.display = 'none';
        }
    }

}
</script>

<input type='radio' name='test' onclick="radiobuttons(first_div)" />Radio 1<br/><div id="first_div">test</div>
<input type='radio' name='test' onclick="radiobuttons(second_div)" />Radio 2<br/><div id="second_div">test2</div>
<input type='radio' name='test' onclick="radiobuttons(third_div)" />Radio 3<br/><div id="third_div">test3</div>

I've tried this code, but it doesnt work. It's displayed in the loop but then hide again immediately. I've tried to insert break; but it doesn't work right either.

 

How can I get it right? Any help?

 

Thank you in advanced.

ayok

 

Link to comment
https://forums.phpfreaks.com/topic/216374-display-divs-with-radiobuttons/
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.