Combine 2 radio button groups?

904 Views Asked by At

I have two radio button groups, and they should be one group.

I need one member of the group to have another name="" than the others. So this one member is not grouped with the others, but i need them grouped too.

One member has a different name but needs to be still grouped. (Only one radio button checkable in both groups)

HTML:

Type: 
Web<input type="radio" name="moep" id="web" checked="checked"> 
Images<input type="radio" name="tbm" id="img" value="isch"> 
Videos<input type="radio" name="tbm" id="videos" value="vid">
News<input type="radio" name="tbm" id="news" value="nws">
Places<input type="radio" name="tbm" id="places" value="plcs"><br />

JS (in extern file if this is relevant, shouldn't be, right?):

$(document).ready(function () {
    $('input[name="tbm"]').change(function() {
        $('input[name="moep"]').prop('checked', false);
    });
    $('input[name="moep"]').change(function() {
        $('input[name="tbm"]').prop('checked', false);
    });
});​

I tried it with several different approaches, but the single name="moep" is checked (by default) and all the other buttons are absolutely independend from it.

Any ideas?

Thanks in advance :)

1

There are 1 best solutions below

1
On BEST ANSWER

In this code, your are un-checking all radio buttons from both groups, except the radio button that was changed.

$('input[name="tbm"],input[name="moep"]').change(function () {
    $('input[name="tbm"],input[name="moep"]')
        .not($(this))
        .prop('checked', false);
});

Demo: http://jsfiddle.net/nabil_kadimi/awcwgq1v/