Search code examples
javascriptinputcheckedunchecked

input javascript checked - unchecked


I have input in body of my html page:

<input id="showElement" type="checkbox" checked="checked" oninput="onShowElementChange()" checked="checked"/>

And in script there is:

  function onShowElementChange(value) {
  scene3dManager.showElement = $('#showElement').is(':checked')
}

function onShowElementChange(value) {
  scene3dManager.showElement = $('#showElement').is(':checked')
}

<input id="showElement" type="checkbox" checked="checked" oninput="onShowElementChange()" checked="checked" />

But, for some reason, it doesn't work ... My input should be clicked by default, and user can unclick it if he chooses to.

Perhaps, there is some mistake in my code, so, im asking for help. Thanks


Solution

  • checked without the value checked should work fine.

    <input type="checkbox" checked/>
    

    Below should work if you remove oninput="onShowSeabedChange()"

    $("#showSeabed").on("click", function(){
       scene3dManager.showSeabed = $('#showSeabed').is(':checked');
    });