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
https://forums.phpfreaks.com/topic/63834-how-do-i-radio-buttons/
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

 

:(

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.