0

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

3
  • 1
    you don't click a select tag, right??you change it. select tag supports event change not click. so your alert is not triggering. change the event from click to change. Commented Mar 19, 2020 at 12:37
  • The select element does not fire a click event - only 'change' and 'input' so your jQuery will not get triggered. Can you explain more what you are trying to achieve? Where is the user typing clicking to fill this box? Commented Mar 19, 2020 at 12:37
  • I want to user show user skills to choose after type some character. This skills gonna show from database with AJAX but at beginning I want to test this 'change' or 'keyup' functions Commented Mar 19, 2020 at 13:24

2 Answers 2

1

Try this

$(document).ready(function () {
     $("#skills").change(function () {
       alert("test")
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

Please mak as verified this answer if its help for you Thank you @pastersky Happy coding :)
0

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

2 Comments

It still doesn't work, I have no result (because I did not load database) but I want press some keys for example scrum and when I press for example 's' and then 'c' I want to show me result from database but now I'm testing and If I click 's' then nothing happens, no alert, no anythink
same, nothing. IMO I'm doing something wrong but IDK what. At laraget website this is working (but full demo), maybe should I try this do full. But If keyup isn't sending any event so that will not work fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.