I want a checkbox to be updated when a value changes. In this short example, if the second checkbox is checked, then the first should be update and checked, too. The functionality of the first checkbox should still stay intact. How can I achieve this?
function onoff() {
currentvalue = document.getElementById('onoff').value;
if (currentvalue == "Off") {
document.getElementById("onoff").value = "On";
console.debug("OFF");
} else {
document.getElementById("onoff").value = "Off";
console.debug("ON");
}
}
function xy() {
document.getElementById('onoff').value = "On";
console.debug("xy");
}
<input type="checkbox" value="On" id="onoff" onclick="onoff();">
<input type="checkbox" value="Off" id="xy" onclick="xy();">
Aucun commentaire:
Enregistrer un commentaire