SyntaxError: переопределение const selectElement - PullRequest
0 голосов
/ 06 июня 2019

Как отображать флажки, где выберите параметр = 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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...