I don't quite understand what you're doing here, Bruce, or why you would want 
to search inside the select options. If you give the select elements id's, 
though, you can use JQuery to grab the selected option in each select tag.

Sent from my iPhone

On 2010-10-15, at 12:35 PM, Bruce Johnson <[email protected]> wrote:

> 
> On Oct 14, 2010, at 12:03 PM, Bruce Johnson wrote:
> 
>> Now, depending on how I search the element tags I get different answers!  
>> 
>> See <http://dbdev2.pharmacy.arizona.edu/jsscratchpad> for all the gory 
>> details...
>> 
>> Why the heck am I getting the results I am?
> 
> For the none of you with an idea :-) it was an obscure issue of the way 
> regular expressions work in javascript.
> 
> basically you specify a regex like:
> 
> thingtosearch = /rain/
> 
> This will find the FIRST instance of the string 'rain' inside of a larger 
> string.
> 
> if you do it like: 
> 
> thingtosearch = /rain/g
> 
> this will find all the instances of 'rain' in the string, advancing to the 
> next each time you search.
> 
> you can test this with the test method: searcher.test(stringtotest). If the 
> search string 'rain' is found in the stringtotest, this returns 'true', 
> otherwise 'false'.
> 
> When you have the g modifer, there's an attribute of searcher 'lastIndex' 
> set; this is the position in the string after the last instance was found.
> 
> Until the test() method returns a false, the lastIndex is NOT reset to 0.
> 
> So I have three strings: 
> 
> "Train in the rain for Spain"
> "I like rainy days in the springtime, darling"
> "rainy days and mondays"
> 
> So I test each one in turn:
> 
> searcher.test("Train in the rain for Spain"), it returns true, and lastIndex 
> is set to 5, which is the position of the last letter of the first 'rain' 
> found. 
> 
> so the loop iterates and the next string comes up: "I like rainy days in the 
> springtime, darling"
> 
> searcher.test("I like rainy days in the springtime, darling") returns true, 
> because it starts at position 5 in the string (the 'k' in 'like', and there 
> is an instance of 'rain' after that. THIS sets the lastindex to  11.
> 
> The next test: "rainy days and mondays" returns False, because there is no 
> 'rain' in 'and mondays'
> 
> Once you know this choice bit of information, which is only implied in the 
> documentation, it's obvious. When you don't you go nuts trying to figure it 
> out.
> 
> The solution?
> 
> don't use the 'g' option, and if you do, force lastIndex to 0 when searching 
> a new string. (which is not normally an issue, because if you're searching 
> long strings for repeats, you're usually doing a structure like:
> 
> while (thingtosearch.test(str)){...} which beaks when it test() returns false.
> 
> And this concludes your "Infuriating javascript 'feature' of the day lesson"
> 
> Stay tuned, I'm sure I'll find more.
> 
> 
> -- 
> Bruce Johnson
> University of Arizona
> College of Pharmacy
> Information Technology Group
> 
> Institutions do not have opinions, merely customs
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "StrataList-OT" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/stratalist-ot?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"StrataList-OT" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/stratalist-ot?hl=en.

Reply via email to