Jump to content

[SOLVED] Display dropdown when radio button is selected


yogibear

Recommended Posts

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

 

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.

Hi

Thanks for your help

 

Works perfectly,  ;D 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

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.