Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rangeSelect($options, min, max)
- {
- return($options.filter(function()
- {
- var r, span = this.innerHTML.match(/[0-9.]+/g); //break the displayed text into numeric tokens
- if(span && (span.length > 0))
- {
- if((span.length >= 2) && (this.innerHTML[0] == "±")) //handle +- split-range
- r = {min: 2 * parseFloat(span[0]), max: 2 * parseFloat(span[1])};
- else if(span.length >= 2) //two tokens, interpret as a range
- r = {min: parseFloat(span[0]), max: parseFloat(span[1])};
- else if(this.innerHTML.match(/up/i)) //look for the keyword "up" for a top-bounded range
- r = {min: -Infinity, max: parseFloat(span[0])};
- else //else assume it's a bottom-bounded range
- r = {min: parseFloat(span[0]), max: Infinity};
- }
- return((r.min <= min) && (max <= r.max)); //this works across the input domain because of +-Infinity bounds
- }));
- };
- function matchSelect($options, regexp)
- {
- return($options.filter(function()
- {
- return(this.innerHTML.match(regexp) != null);
- }));
- }
- // select all optionas in pv659 between 12 and 16
- rangeSelect($('select[name="pv659"]').children(), 12, 16).attr("selected", true);
- // select all options in pc1113 that contain "usb" (case-insensitive)
- matchSelect($('select[name="pv1113"]').children(), /usb/i).attr("selected", true);
Add Comment
Please, Sign In to add comment