0
I record meals this way, as shown in the picture:
I created the button Apply to All, which is to, after filling in the first day of the month, fill in the remaining days of the month with the same data. For example:
That’s how I mark day one:
By clicking the button Applies to All fill in the remaining days in the same way:
Code:
<input type='button' id='elemento' value='Aplicar a Todos' />
<td bgcolor='$color' data-semana=''><font size='2px'/>
<input id='firstCB{$year}{$month}{$day}' type='checkbox' name='arrachar[$year, $month, $day][dia]' value='$year-$month-$day'>$year-$month-$day <br />
<div>
<input type='checkbox' class='checkbox' name='arrachar[$year, $month, $day][OpcaoA]' value='Peq_Almoço'>Peq. Almoço</div> <div><input ref='firstCB{$year}{$month}{$day}' min='0' oninput='this.value = Math.abs(this.value)' type='number' name='arrachar[$year, $month, $day][Qtd]' value='$marcado_pequeno_qtd' />
<br />
</div>
<div>
<input type='checkbox' class='checkbox1' name='arrachar[$year, $month, $day][opcaoB]' value='Almoço'>Almoço</div> <div><input ref='firstCB{$year}{$month}{$day}' min='0' oninput='this.value = Math.abs(this.value)' type='number' name='arrachar[$year, $month, $day][Qtd1]' value='$marcado_almoco_qtd'/>
<br />
</div>
</td>
Javascript:
$('#elemento').on('click', function(){
var inputs = [...document.querySelectorAll("[type='checkbox']")];
if(inputs == 'checked'){ // condição
$('.checkbox').prop('checked', true);
$('.checkbox1').prop('checked', true);
}
});
I wanted you to select all checkboxes on every day as on day 1 and also fill in the inputs with the same value as day 1. The way I have the condition does not select any checkbox when clicking the button Apply to all.
I’m trying this way:
<input type='button' id='elemento' value='Aplicar a Todos' />
<td><input id='firstCB{$year}{$month}{$day}' type='checkbox' name='arrachar[$year, $month, $day][dia]' value='$year-$month-$day'>$year-$month-$day <br />
<div><input type='checkbox' class='checkbox' name='arrachar[$year, $month, $day][OpcaoA]' value='Peq_Almoço'>Peq. Almoço</div> <div><input ref='firstCB{$year}{$month}{$day}' min='0' oninput='this.value = Math.abs(this.value)' type='number' class='checkbox' name='arrachar[$year, $month, $day][Qtd]' value='$marcado_pequeno_qtd' /> <br /></div>
<div><input type='checkbox' class='checkbox1' name='arrachar[$year, $month, $day][opcaoB]' value='Almoço'>Almoço</div> <div><input ref='firstCB{$year}{$month}{$day}' min='0' oninput='this.value = Math.abs(this.value)' type='number' class='checkbox1' name='arrachar[$year, $month, $day][Qtd1]' value='$marcado_almoco_qtd'/> <br /> </div></td>
$('#elemento').on('click', function(){
var inputs = $('.checkbox');
inputs.each(function(index, element){
if(element.checked) {
var children = $(element).parent().parent().children('.checkbox');
children.each(function(i, child){
$(child).prop('checked', true);
});
}
});
});
But do not select the remaining days with the values of day 1 of the month.
i can’t separate the days in html by div, because I create the days in loop. html is inside a variable.
– Bruno
@Bruno Provide the html of your complete example to work with the real elements you have. In your example you use something that seems to me to be php variables of some framework.
– MauroAlmeida
updated the question with the missing code.
– Bruno
@Bruno I needed was the resulting html, instead of the image it was good to have something that could manipulate using JS.
– MauroAlmeida
@Bruno no, I’m talking about the html with the full calendar and all the checkboxes, as you have in your image.
– MauroAlmeida
I have updated the code with the full calendar that generates html
– Bruno
see in chat the html that generated, I think that put in the question will not be well accepted because it is very code
– Bruno