OnChange does not work on radio buttons [duplicate]

Refresh

March 2019

Views

148 time

1

I do not know why the onchange function does not trigger if I Switch the Radio Buttons.

I only get the console message if I click on each Radio the first time, but after switching the Radio I do not the a console Output.

var drawingArrow = document.getElementById('drawing-arrow-shape'),
    drawingCircle = document.getElementById('drawing-circle-shape'),

drawingCircle.onchange = function() {
    console.log("on change circle btn");
};

drawingArrow.onchange = function() {
    console.log("on change arrow btn");
};

    <label class="btn btn-default btn-lg">
        <input type="radio" name="drawing-arrow-shape" id="drawing-arrow-shape">
        <i class="glyphicon glyphicon-arrow-right"></i>
    </label>
    <label class="btn btn-default btn-lg">
        <input type="radio" name="drawing-circle-shape" id="drawing-circle-shape">
        <i class="glyphicon glyphicon-record"></i>
    </label>

1 answers

2

you have to give the radiobuttons the same name something like name="drawing-shape"