Capturing the contents of <select>
Posted
by joey mueller
on Stack Overflow
See other posts from Stack Overflow
or by joey mueller
Published on 2010-05-28T03:06:31Z
Indexed on
2010/06/03
15:44 UTC
Read the original article
Hit count: 293
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!
© Stack Overflow or respective owner