0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

都道府県検索 JS+PHP セレクトボタン選択でJSを発火して検索

Last updated at Posted at 2022-02-16

php

               <form action="/" method="GET">
                    <input type="hidden" name="is_area" value="1" />
                    <select id="change_js" name="area_id" style="background: #0abab5;padding:10px;color:white;text-align:center;">
                        <option style="text-align:center;" value="">全国</option>
                        @foreach($prefecture_list as $prefecture)
                            <option value="{{ $prefecture->id }}" @if($area == $prefecture->id) selected @endif>{{$prefecture->prefecture_name}}</option>
                        @endforeach
                    </select>
                    <button id="btn-upload" type="submit" ></button>
                </form>

js

$(document).ready(function(){
    const selected = document.getElementById("change_js");
        selected.onchange = function() {
        document.getElementById('btn-upload').click();
    };
    let is_area = '{{ $area == "" ? "0" : "1" }}';
    if (is_area == '1'){
        document.getElementById("area_search").click();
    }

}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?