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

 

Link to comment
Share on other sites

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
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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