You may also like to read how to get the value of the selected dropdown option using jQuery. I use Select2 and I forgot to account for the placeholder when marrying it up to an array. In my function I'm using a variable for the id of the select box I'm targeting. To learn more, see our tips on writing great answers. Topic: JavaScript / jQuery Prev|Next. What does a faster storage device affect? site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. Select the option from the select box given above. $ ('#aioConceptName').change (function() { var $option = $ (this).find ('option:selected'); //Added with the EDIT var value = $option.val (); //returns the value of the selected option. ;), @JoePC no its not. How can I convert a string to boolean in JavaScript? jQuery Practical Exercises with Solution: Get the selected value and currently selected text of a dropdown box using jQuery. returns null when no option is selected and an array containing the Below will give innerText. Did "Antifa in Portland" issue an "anonymous tip" in Nov that John E. Sullivan be “locked out” of their circles because he is "agent provocateur"? Probably your best bet with this kind of scenario is to use jQuery's change method to find the currently selected value, like so: I prefer this method because you can then perform functions for each selected option in a given select field. such as input, select and textarea. Are the longest German and Turkish words really single words? In the case of select elements, it Because :selected is a jQuery extension and not part of the CSS specification, queries using :selected cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. So why not avoid all the jQuery magic and just pass the selected value as an argument to the action call? The code is identical to the first method in the question. The change event executes the code when you change the select box option. Now you can call $('#aioConceptName').val() instead of all this :selected voodoo being suggested by others. Works for me in recent projects so it is worth to look on it. I'm a little bit confused about how to get an index of a selected option from a HTML