Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ngoquocdat's avatar

Change event doesn't work with select

When I choose another option nothing happens

My select

<select class="form-control select2 select_location" name="group_id">
    @foreach($categories as $category)
        <option value="{{ $category->id }}" @if($category->id == request()->get('group_id')) selected @endif>{{ $category->name }}</option>
    @endforeach
</select>

My jquery

$('.select_location').on('change', function () {
    console.log('hello')
})
0 likes
17 replies
ngoquocdat's avatar

i tried

$(".select_location").change(function () {
            console.log('hello')
})

but not working

frankielee's avatar

Is jquery loaded?

Try to assign an id to the

Example


<select class="form-control select2 select_location" name="group_id" id="test">

</select>

$("#test").change(function () {
            console.log('hello')
})
ngoquocdat's avatar

I try to use change at the input, it works but select doesn't

ngoquocdat's avatar

Uncaught TypeError: $(...).select2 is not a function

frankielee's avatar

Make sure your script loading is in correct order like below:

  1. jQuery, //if you are using laravel, it probably is app.js
  2. select2,
  3. your custom js files
frankielee's avatar

No problem. Please select the best answer to close the thread.

Please or to participate in this conversation.