[英]How to check and uncheck checkbox automatically
I'm doing a page where i can display a list of data with checkboxes. 我正在做一个页面,我可以在其中显示带有复选框的数据列表。 then i will automatically check with database and if the data is there, the checkbox will be checked. 然后我将自动检查数据库,如果有数据,则将选中该复选框。 What i want to do now is, lets say the checkbox is checked automatically, andwhen i unchecked it myself and save, it will update the data in database. 我现在想做的是,假设该复选框已自动选中,当我自己取消选中并保存时,它将更新数据库中的数据。
Example of my coding: 我的编码示例:
<form action="{{URL::to('/granted/'.$d->id)}}" method="get">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
@foreach($var as $v)
<table style="margin-left:20px;">
<caption>{{$v->module_groupname}}</caption>
@foreach($name as $n)
<?php if($n->module_groupname == $v->module_groupname){?>
<tr><td width="80"><input type="checkbox" name="module_code[]" value="{{ $n->module_code }}"
<?php foreach($priv as $p){
if($p->user_id == $d->id){
if($p->module_code == $n->module_code){
echo 'checked="checked"';
}
}
}?>></td>
<td width="150">{{$n->module_groupname}}</td>
<td width="200">{{ $n->module_desc}}</td>
</tr> <?php } ?>
@endforeach
</table>
<hr>
@endforeach
<input type="submit" value="select" class="btn btn-s btn-success">
</form>
i've been advised to lookup for PLUS statement oracle but i couldnt find how 建议我查找PLUS语句oracle,但我找不到如何
for automatically checked you need set Attribute checked for that checkbox 对于自动检查,您需要设置选中该复选框的属性
https://www.w3schools.com/tags/att_input_checked.asp https://www.w3schools.com/tags/att_input_checked.asp
for doing this by js you follow this url ! 为了通过js做到这一点,请遵循以下网址! say setAttribute property 说setAttribute属性
https://www.w3schools.com/jsref/met_element_setattribute.asp https://www.w3schools.com/jsref/met_element_setattribute.asp
hope this will help you 希望这个能对您有所帮助
<input type="checkbox" @if(compare) checked @endif />
I recommend you to look at this code and try to reformat you own code. 我建议您看一下这段代码,然后尝试重新格式化自己的代码。 You are using blade so use it everywhere. 您正在使用刀片,因此请随处使用。
<form action="{{URL::to('/granted/'.$d->id)}}" method="get">
{{ csrf_field() }}
@foreach($var as $v)
<table style="margin-left:20px;">
<caption>{{$v->module_groupname}}</caption>
@foreach($name as $n)
@if($n->module_groupname == $v->module_groupname)
<tr>
<td width="80"><input type="checkbox" name="module_code[]" value="{{ $n->module_code }}" {{ $priv->contains('user_id', $d->id) && $priv->contains('module_code', $n->module_code) ? 'checked' : '' }}></td>
<td width="150">{{$n->module_groupname}}</td>
<td width="200">{{ $n->module_desc}}</td>
</tr>
@endif
@endforeach
</table>
<hr>
@endforeach
<input type="submit" value="select" class="btn btn-s btn-success">
I think you can use the contains function if your $prev variable is a model. 我认为如果$ prev变量是模型,则可以使用contains函数。
I didn't test this code so try if it works 我没有测试此代码,因此请尝试是否有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.