0
I have 3 checkbox
and 2 inputs
. The second checkbox
is parent()
of 1 input type number
and the third checkbox
is parent()
of 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>";}
To automatically mark 2 and 3 checkbox
by placing a value greater than zero in the input type number
have this 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>
When filling in 1 or 2 input type number, you also automatically mark the checkbox
parent()
of it, I also want you to automatically mark the first checkbox
date.
It is possible to adapt my script to do this?
The @osiris85 answer works in the example he gave, but when applying it in my code there is a problem, I will explain.
If I apply the @osiris85 response in my code, when filling the inputs
, only selects the date of day 1 and not the date according to the day where the input
is.
For example: fill in inputs
2018-11-18 and automatically mark only checkbox
of the day 2018-11-01
I check that here is giving the result I want, but applying in my code the checkbox still does not appear marked
– user130631
adcionó id to input
<input id='firstCB' type='checkbox
?– osiris85
yes I added to html
– user130631
try to remove the 3 tags
</font></center></td>
– osiris85
the result is the same...
– user130631
got an error in the developer console?
– osiris85
There is no error in the console and selects the date. But there is a problem, I put value on different inputs, just select the date of day 1 and not the date on which the input is. For example, I put value in the input of day 24 and select the date of day 1. I edited the question with the other part of the code.
– user130631