Web DesignjQuery

Get Option Values from a Select

This is an easy way to grab all the option values from any regular html select, and print them to your Firebug console as a comma separated list. (I found this useful when I needed to grab the state names listed on a previous version of a company website.)


var newArray = [];
var list = $('#selectID').find('option');
for(var i = 0; i < list.length; i++) {
newArray[i] = list[i].text;
}
console.log(newArray.join(", "));

Leave a Reply

“Fear is the path to the dark side. Fear leads to anger. Anger leads to hate. Hate leads to suffering”

—Master Yoda

I'm a web designer and writer based out of Nashville, TN, where I live with my husband, step-daughter, and chihuahua.

moonkatcreations at gmail dot com