Depending on the Snippet
below, when clicking on a checkbox
, the others should be deselected, but only happens if you click them from right to left, if I click them from left to right, nothing happens.
Does anyone know what's going on?
Explanation:
When I select a checkbox
, I'll apply an X filter to a Y field.
There are already other Radio Button
in use, and my upper one wants the checkbox
to be used.
var d = document.getElementById('dinheiro');
var p = document.getElementById('porcentagem');
var h = document.getElementById('hora');
function marcaDesmarca() {
if (d.checked) {
document.getElementById('porcentagem').checked = false;
document.getElementById('hora').checked = false;
} else if (p.checked) {
document.getElementById('dinheiro').checked = false;
document.getElementById('hora').checked = false;
} else if (h.checked) {
document.getElementById('dinheiro').checked = false;
document.getElementById('porcentagem').checked = false;
}
}
<div style='position: relative;'>
<input id="dinheiro" name="tipoentrada" type="checkbox" value="D" onclick="marcaDesmarca()"> <label style='display: contents;'>Dinheiro</label>
<input id="porcentagem" name="tipoentrada" type="checkbox" value="P" onclick="marcaDesmarca()"> <label style='display: contents;'>Porcentagem</label>
<input id='hora' name="tipoentrada" type="checkbox" value="H" onclick="marcaDesmarca()"> <label style='display: contents;'>Hora/Minuto</label>
</div>