jQuery - auto checked radio button depend on first selection by Norlihazmey Ghazali

http://stackoverflow.com/questions/32242524/how-to-select-radio-button-automatically/32242818#32242818

by Norlihazmey Ghazali

HTML

<div>
    <label>
        <input type="radio" id="q128" name="quality[21]" value="1" />1</label>
    <label>
        <input type="radio" id="q129" name="quality[21]" value="2" />2</label>
</div>
<div>
    <label>
        <input type="radio" id="q128" name="quality[22]" value="1" />1</label>
    <label>
        <input type="radio" id="q129" name="quality[22]" value="2" />2</label>
</div>

JavaScript

$('div').on('click', '[type="radio"]', function () {
    var radioValue = $(this).val();

    $(this).closest('div').siblings().find('[type="radio"]').not('[value="' + radioValue + '"]').prop('checked', true);

});