Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
I am having two radio buttons 'a' and 'b' and if one selects 'a' then I want different sort of rows or options to get displayed and if one selects 'b' then other.
Can this be done in html or I have to use java script or php
Posted
Comments
enhzflep 22-Jul-13 7:20am    
Well, php won't help - think of php as an automated typewriter - i.e all it does is output html/js/css/media. It does so with the ability to perform calculations, but at the end of the day, all it does is provide output.

Javascript is what you'll need to use.
See Brian's answer
Sergey Alexandrovich Kryukov 22-Jul-13 18:30pm    
There is no such thing as "Java script": Java is not a scripting language ;-) If you meant to say "JavaScript", this is something totally unrelated to "Java".
And "to use java script or php" shows complete confusion with the very basics. PHP is the server-side scripting language...
—SA

1 solution

If you really don't want to use Javascript, here's a way to accomplish this with HTML and CSS3 only.

Place each radio button directly before its associated section to show or hide. This way, you can take advantage of the + adjacent sibling selector, in combination with the :checked pseudo-class (CSS3 only), to show the section only if it's preceded by a checked radio button:
CSS
input:checked+.TargetSection {
    display: block;
}

With absolute positioning, the target section can still be displayed below the radio buttons, even though the markup is mixed together.

Here's a sample: http://jsfiddle.net/4uM8T/[^]
 
Share this answer
 
Comments
enhzflep 22-Jul-13 20:21pm    
Brilliant! Great answer. My +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900