yogibear Posted August 23, 2008 Share Posted August 23, 2008 Hi all I’m having a little trouble with JavaScript and knowing very little about JavaScript I’m not doing very well. I have two radio buttons on my page, when the first is selected a drop down menu appears next to it. This part works perfectly, thanks to an example I found. The second radio button should display a total of six drop down menus. I can’t figure out how to modify what I have to make it work. This is what I have for the first radio button <SCRIPT language = JavaScript> function show() { var i = 0; var el; while(el = document.getElementsByName("radio1")[i++] ) { // alert(i); (document.getElementById('radio'+i).checked) ? document.getElementById('drop'+i).style.display="block" : document.getElementById('drop'+i).style.display="none" } } </script> Please can you tell me what I need to change? Best wishes Yogi Link to comment https://forums.phpfreaks.com/topic/121023-solved-display-dropdown-when-radio-button-is-selected/ Share on other sites More sharing options...
JasonLewis Posted August 23, 2008 Share Posted August 23, 2008 Try using something like this: function showSecondRadio(){ if(document.getElementById("radio2").checked){ for(i = 0; i < 6; i++){ document.getElementById("dropdown_"+i).style.display = "block"; } } } Just an example, but hopefully you get the idea. Link to comment https://forums.phpfreaks.com/topic/121023-solved-display-dropdown-when-radio-button-is-selected/#findComment-623984 Share on other sites More sharing options...
yogibear Posted August 24, 2008 Author Share Posted August 24, 2008 Hi Thanks for your help Works perfectly, the only thing thats a little weird is the textboxes went from being displayed in 2 sets of 3 to being displayed in one line. Puting them in a table with a cell each solved this problem. Best wishes yogi Link to comment https://forums.phpfreaks.com/topic/121023-solved-display-dropdown-when-radio-button-is-selected/#findComment-624184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.