Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap radio buttons do not work

I am using radio buttons in Bootstrap 4 like this:

    <div class="btn-group" data-toggle="buttons">
        <label class="btn btn-primary active">
            <input type="radio" id="physical-option" onclick="alert('Physical!')" checked="checked" /> Physical
        </label>
        <label class="btn btn-primary">
            <input type="radio" id="scenery-option" onclick="alert('Scenery!')" /> Scenery
        </label>
    </div>

As you can see I have the onclicks there. But, when I click them, nothing happens! Is this a bug in Bootstrap?

like image 613
MCMastery Avatar asked Oct 30 '22 21:10

MCMastery


1 Answers

Can you put the onclick on the label instead of the radio? I think bootstrap makes the label the radio trigger instead of the actual radio button.

Have a look at the scenery button:

https://jsfiddle.net/zf7p2Lbd/

    <label class="btn btn-primary" onclick="alert('Scenery!')">
        <input type="radio" id="scenery-option" /> Scenery
    </label>
like image 168
Joseph Young Avatar answered Nov 11 '22 22:11

Joseph Young