skip to Main Content

Hello I have issue with my jquery code, because when I want to press any key to get query from database that is not working (it is not showing any alert). I think my ajax isn’t working very well because I tried to copy other code and didn’t work. I want to get data from database with my skills to choose in options

jQuery code

$(document).ready(function () {
    $("#skills").click(function () {
      alert("test")
    });
  });

<select class="select2bs4" multiple="multiple" name="ums[]" data-placeholder="Skills"
                style="width: 100%;" id="skills">
</select>

And I want to do when I press any key then should show any result in multiple select but at beginning didn’t show any alert yet.

I tried to do like “Select2 and Laravel: Ajax Autocomplete” from Laraget website and that wasn’t working too

EDIT____
If it’s only input with type ‘text’ it’s working fine to show alert

Thank you in advance

2

Answers


  1. Select will not work with click but with change , but if you want change when you write in select like search bar , replace this :

    $("#skills").click(function () {
      alert("test")
    });
    

    to this if you want to get the change option :

    $("#skills").on('change',function () {
      alert("test")
    });
    

    or this if you want to handle user input :

    $("#skills").on('keyup',function () {
      alert("test")
    });
    
    Login or Signup to reply.
  2. Try this

    $(document).ready(function () {
         $("#skills").change(function () {
           alert("test")
        });
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search