|
|
| (同じ利用者による、間の7版が非表示) |
| 1行目: |
1行目: |
| document.addEventListener('DOMContentLoaded', function () {
| |
| const form = document.getElementById('searchForm');
| |
| if (!form) return;
| |
|
| |
|
| // ---- SUBMIT ----
| |
| form.addEventListener('submit', function () {
| |
| const ids = ['searchText','genre','station','budget_min','budget_max'];
| |
| ids.forEach(id => {
| |
| const el = document.getElementById(id);
| |
| if (el && el.value.trim() === '') {
| |
| el.removeAttribute('name');
| |
| }
| |
| });
| |
| });
| |
|
| |
| // ---- LOAD FROM URL ----
| |
| const params = new URLSearchParams(window.location.search);
| |
| params.forEach((value, key) => {
| |
| document.querySelectorAll(`[name="${key}"]`).forEach(el => {
| |
| if (el.type === "checkbox" || el.type === "radio") {
| |
| if (el.value === value) el.checked = true;
| |
| } else {
| |
| el.value = value;
| |
| }
| |
| });
| |
| });
| |
|
| |
| // ---- CLEAR BUTTON ----
| |
| const clearBtn = document.querySelector('.clear-btn');
| |
| if (clearBtn) {
| |
| clearBtn.addEventListener('click', function () {
| |
| form.reset();
| |
| });
| |
| }
| |
| });
| |