Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all selected options elements from all select elements in a form

Hi all and thanks for taking the time to answer my question.

I have a form with 6 select elements with the class of "skillLevel". I need to get (preferably in an array] the values of each select element using jQuery.

How can I do that?

like image 999
Dragan Avatar asked Sep 17 '12 11:09

Dragan


People also ask

What is the return type of get all selected options?

selectedOptions returns a HTMLCollection , not an Array .

How to get select option value?

If you want to get selected option value, you can use $(select element). val() .

How to get value of selected option using jQuery?

Use the jQuery: selected selector in combination with val () method to find the selected option value in a drop-down list.


1 Answers

You can use map method:

var arr = $('select.skillLevel').map(function(){
              return this.value
          }).get()

arr is an array of values.

like image 91
undefined Avatar answered Oct 19 '22 03:10

undefined