pastersky
pastersky

Reputation: 11

Loading data from database in select option html - Laravel

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

Upvotes: 0

Views: 852

Answers (2)

Julien Rajerison
Julien Rajerison

Reputation: 131

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")
});

Upvotes: 0

VIKAS KATARIYA
VIKAS KATARIYA

Reputation: 6005

Try this

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

Upvotes: 1

Related Questions