// This decoument ready can be used as setting the default value. If you remove the "checked", from the first radiobutton..then both selects will be hidden and of course none of the radiobuttons will be checked
$(document).ready(function() {
// Lets get the default group by checking which radiobutton is checked
var current_checked = $('select[name=group]:selected');
// If we have a default value on load, then:
if (current_checked) {
// We pick the select matching to our radiobuttons value and make it visible
$('select[name=group_' + current_checked.val() + ']').show();
// PS: You can use .fadeIn() instead of show()
}
});
// Now lets catch the click action on any of the radiobuttons
$('select[name=group]').change(function () {
// Lets get the group ID (a or b), from radiobuttons value
var this_group = $(this).val();
// First lets make both selects equal and hide them
$('select.hidden_select').hide();
// Then display the currently active select
$('select[name=group_' + this_group + ']').show();
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.