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(", "));

This entry was posted in jQuery. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>