Jump to content

How do I... (radio buttons..)


php_novice2007

Recommended Posts

Hi,

 

I've got two radio buttons, and I want to call a javascript function when one of them is clicked to display some text, if the other one is selected I don't want the text to be displayed..

 

So far I've got:

<input type=radio name="u1choice" checked onclick="radioclick(this)" value="u1all">All data<br>
<input type=radio name="u1choice" onclick="radioclick(this)" value="u1selected">Selected period<br>
<div id="collapseDate1" style="display:none">
   What period? ....
</div>

function radioclick(rbutton) {


}

 

So if Selected period is selected, I want "What period?  ...." to be displayed, if All data is selected, I want it hidden. I don't know what to write in the radioclick() function.

 

Thanks for any help!

Link to comment
Share on other sites

I just tried:

 

function radioclick(rbutton) {
    if (rbutton[0].checked) {  //all selected
        alert("all selected");
        //document.getElementById(str1).style.display = 'none';
    } else if (rbutton[1].checked) {  //selected dates selected
        alert("selected date selected");
        //document.getElementById(str1).style.display = '';
    } else {
        alert("???");
    }
}

 

And I'm getting an error which says '0.checked' is null or not an object

 

:(

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.