Guest User

Untitled

a guest
May 24th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. function rangeSelect($options, min, max)
  2. {
  3. return($options.filter(function()
  4. {
  5. var r, span = this.innerHTML.match(/[0-9.]+/g); //break the displayed text into numeric tokens
  6. if(span && (span.length > 0))
  7. {
  8. if((span.length >= 2) && (this.innerHTML[0] == "±")) //handle +- split-range
  9. r = {min: 2 * parseFloat(span[0]), max: 2 * parseFloat(span[1])};
  10. else if(span.length >= 2) //two tokens, interpret as a range
  11. r = {min: parseFloat(span[0]), max: parseFloat(span[1])};
  12. else if(this.innerHTML.match(/up/i)) //look for the keyword "up" for a top-bounded range
  13. r = {min: -Infinity, max: parseFloat(span[0])};
  14. else //else assume it's a bottom-bounded range
  15. r = {min: parseFloat(span[0]), max: Infinity};
  16. }
  17.  
  18. return((r.min <= min) && (max <= r.max)); //this works across the input domain because of +-Infinity bounds
  19. }));
  20. };
  21.  
  22. function matchSelect($options, regexp)
  23. {
  24. return($options.filter(function()
  25. {
  26. return(this.innerHTML.match(regexp) != null);
  27. }));
  28. }
  29.  
  30. // select all optionas in pv659 between 12 and 16
  31. rangeSelect($('select[name="pv659"]').children(), 12, 16).attr("selected", true);
  32.  
  33. // select all options in pc1113 that contain "usb" (case-insensitive)
  34. matchSelect($('select[name="pv1113"]').children(), /usb/i).attr("selected", true);
Add Comment
Please, Sign In to add comment