OnChange does not work on radio buttons [duplicate]


March 2019


148 time


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 class="btn btn-default btn-lg">
        <input type="radio" name="drawing-circle-shape" id="drawing-circle-shape">
        <i class="glyphicon glyphicon-record"></i>

1 answers


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