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! Quote Link to comment 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 Quote Link to comment 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... Quote Link to comment 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'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.