php_novice2007 Posted August 8, 2007 Share Posted August 8, 2007 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 More sharing options...
php_novice2007 Posted August 8, 2007 Author Share Posted August 8, 2007 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 https://forums.phpfreaks.com/topic/63834-how-do-i-radio-buttons/#findComment-318161 Share on other sites More sharing options...
ToonMariner Posted August 8, 2007 Share Posted August 8, 2007 you are passing 'this' to the function so lose the [0] - you are passing the object itself NOT an array... Link to comment https://forums.phpfreaks.com/topic/63834-how-do-i-radio-buttons/#findComment-318263 Share on other sites More sharing options...
php_tom Posted August 8, 2007 Share Posted August 8, 2007 To hide the text, you could also try document.getElementById(str1).style.visibility='visible'; -- and -- document.getElementById(str1).style.visibility='hidden'; Link to comment https://forums.phpfreaks.com/topic/63834-how-do-i-radio-buttons/#findComment-318530 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.