Capturing the contents of <select>
- by joey mueller
I'm trying to use a regular expression to capture the contents of all option values inside an HTML select element
For example, in:
<select name="test">
<option value="blah">one</option>
<option value="mehh">two</option>
<option value="rawr">three</option>
</select>
I'd like to capture one two and three into an array.
My current code is
var pages = responseDetails.responseText.match(/<select name="page" .+?>(?:\s*<option .+?>([^<]+)<\/option>)+\s*<\/select>/);
for (var c = 0; c<pages.length; c++) {
alert(pages[c]);
}
But it only captures the last value, in this case, "three".
How can I modify this to capture all of them?
Thanks!