views:

234

answers:

1

I have 3 divs that contain radio with labels and beneath each radio button I would like to show/hide a form based on whether the radio is selected or not.

Code idea:

<div id="radio1"></div>
<div id="form1"></div>

<div id="radio2"></div>
<div id="form2"></div>

<div id="radio3"></div>
<div id="form3"></div>

Using prototype does anyone have any basic idea or suggestion on the best way to accomplish this. Any suggested scripts or links would be greatly appreciated. I am a newbie to prototype and having a hard time grasping the concept or finding anything helpful online. In theory I wouldn't think this would be too complicated but thanks in advance for any help.

A: 

Use this pattern:

<div onclick="$('form1').toggle()" id="radio1"></div>
<div id="form1" style="display"none"></div>

You can chain these together to control other elements as well:

<div onclick="$('form1').toggle();$('form2').hide();$('form3').hide()" id="radio1"></div>
<div id="form1" style="display"none"></div>

There are better ways to do this, such as selecting all of the elements that have the same class, hiding them, then showing the clicked element. But from a beginner's point of view, this should do what you want.

Diodeus
You should probably mention that this is using jQuery. The question specified prototype.
Atømix
Looks like Prototype to me
John Conde
Thanks so much for the quick response. From what I understand after trying the above that will only work if clicking on the div. I was a bit unclear but inside of each div (radio1, radio2, radio3) there is a radio button. What I am trying to accomplish is that if the radio button is selected the next form div should show. If another radio is selected it should not show but only the form in the next div. So basically, if radio selected show form with id, if not selected, hide the form.Hope that helps to clarify a bit but thanks for your super fast response.
pixelflips
Sure See my edits, and don't forget to press the UP arrow to vote-up any answers you find helpful.
Diodeus