Marc Grabanski

jQuery Tip - Getting Select List Values

July 22, 2008

logo jquery 1

A friend asked me a simple question today, but it is worth noting because I have asked the same before, “How do you get the current value from a select list?” To get the current value is very simple using val() .


But sometimes you may need to get the selected option’s text. This is not as straight forward. First, we get the selected option with :selected selector. Then once we have the option, we can get the text with the function, text().

$('#selectList :selected').text()

Note on July 23 `9:14AM: HoyaSaxa93 wrote in to ask how to get values from select multiples.

This would be how to set a select multiple to an array called, “foo”:

var foo = []
$('#multiple :selected').each(function(i, selected) {
  foo[i] = $(selected).text()
Edit Post on Github

Marc Grabanski

Web Development, Business and Life Thoughts from Marc Grabanski – Founder, CEO & UI Developer of Frontend Masters

<< Response to Full-Time EmploymentOde to JWT Minneapolis >>