Tenho 3 checkbox
e 2 inputs
. A segunda checkbox
é parent()
do 1 input type number
e a terceira checkbox
é parent()
do 1 input type number
:
$calendar .= "<td bgcolor='$color' data-semana=''><font size='2px'/>
<input type='checkbox' name='arrachar[$year, $month, $day][dia]' value='$year-$month-$day' $marcado_data $disabled> <strong style='color:#5ca2df'>$year-$month-$day</strong> <br />
<div style='width:60%;position:relative;float:left'><input type='checkbox' name='arrachar[$year, $month, $day][OpcaoA]' value='Peq_Almoço' $marcado_pequeno $disabled> <strong style='color: #000000'>Peq. Almoço</strong></div> <div style='width:40%;position:relative;float:left'><input $disabled min='0' oninput='this.value = Math.abs(this.value)' type='number' name='arrachar[$year, $month, $day][Qtd]' value='$marcado_pequeno_qtd' style='width:65px; height: 22px' /> <br /> </div>
<div style='width:60%;position:relative;float:left'><input type='checkbox' name='arrachar[$year, $month, $day][opcaoB]' value='Almoço' $marcado_almoco $disabled> <strong style='color: #000000'>Almoço</strong></div> <div style='width:40%;position:relative;float:left'><input $disabled min='0' oninput='this.value = Math.abs(this.value)' type='number' name='arrachar[$year, $month, $day][Qtd1]' value='$marcado_almoco_qtd' style='width:65px; height: 22px' /> <br /> </div></font></center></td>";}
Para marcar automaticamente a 2 e 3 checkbox
ao colocar um valor maior que zero no input type number
tenho este script
:
<script>
var inputs_ = document.querySelectorAll("[type='number'][name^='arrachar']");
for(var x=0; x<inputs_.length; x++){
inputs_[x].addEventListener("input", function(){
var box = this.parentNode.previousElementSibling.querySelector("[type='checkbox']");
box.checked = this.value > 0 ? true : false;
});
}
</script>
Ao preencher o 1 ou 2 input type number, além de marcar automaticamente a checkbox
parent()
dele, quero que também marque automatica a primeira checkbox
da data.
É possível adaptar o meu script para fazer isso?
A resposta do @osiris85 funciona no exemplo que ele deu, mas ao aplica-la no meu código existe um problema, vou passar a explicar.
Se aplicar no meu código a resposta do @osiris85, ao preencher os inputs
, só selecciona a data do dia 1 e não a data de acordo com o dia onde o input
se encontra.
Por exemplo: preencho os inputs
do dia 2018-11-18 e marca automaticamente só a checkbox
do dia 2018-11-01