如何显示复选框,其中选择选项= category_id。
选择一个选项后,我试图显示复选框。
我想要同一件事。但是有了Laravel和数据库。
但是为什么选择一个我会得到浏览器白页?
firefox中的检查器
index.blade.php
<form action="{{ route('computers.store') }}" method="post">
{{ csrf_field() }}
<div class="form-group">
<select id="select" name="category_id" class="form-control" onchange="displayBoxes()">
@foreach($categories as $category)
<option data-description="{{ $category->description }}" value="{{ $category->id }}">{{ $category->name }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<p id="description"></p>
</div>
<div class="form-group d-none box17">
<p></p>
@foreach ($computers->where('category_id', 2) as $computer)
<input type="checkbox" id="{{ $computer->latin }}">
<label for="{{ $computer->latin }}">{{ $computer->name }}</label>
@endforeach
</div>
<div class="form-group d-none box18">
<p></p>
@foreach ($computers->where('category_id', 3) as $computer)
<input type="checkbox" id="{{ $computer->latin }}">
<label for="{{ $computer->latin }}">{{ $computer->name }}</label>
@endforeach
</div>
<div class="form-group d-none box19">
<p></p>
@foreach ($computers->where('category_id', 4) as $computer)
<input type="checkbox" id="{{ $computer->latin }}">
<label for="{{ $computer->latin }}">{{ $computer->name }}</label>
@endforeach
</div>
<div class="form-group">
<button class="btn btn-primary">ادامه</button>
</div>
</form>
script.js
const selectElement = document.querySelector('#select');
selectElement.addEventListener('change', (event) => {
let boxes = document.querySelectorAll('div');
boxes.forEach(function(e) {
e.classList.add('d-none');
});
});
document.querySelector('.box' + selectElement.options[selectElement.selectedIndex].value).classList.remove('.d-none');
我在控制台中收到此错误
SyntaxError:重新声明const selectElement