code_junkie

Loop through <select> and build array in the format: &ldquo;value1&rdquo;,&ldquo;value2&rdquo;,&ldquo;value3&rdquo;

Nov 11th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. $("#CityLocal").autocompleteArray(
  2. [
  3. "Aberdeen", "Ada", "Adamsville", "Zoar" //and a million other cities...
  4. ],
  5. {
  6. delay:10,
  7. minChars:1,
  8. matchSubset:1,
  9. onItemSelect:selectItem,
  10. onFindValue:findValue,
  11. autoFill:true,
  12. maxItemsToShow:10
  13. }
  14. );
  15.  
  16. $("#CityLocal").autocompleteArray(
  17. [
  18. MyBigArrayOfOptions
  19. ],
  20. {
  21. delay:10,
  22. minChars:1,
  23. matchSubset:1,
  24. onItemSelect:selectItem,
  25. onFindValue:findValue,
  26. autoFill:true,
  27. maxItemsToShow:10
  28. }
  29. );
  30.  
  31. $(document).ready(function(){
  32. // array of option elements' values
  33. var optionValues = [];
  34. // array of option elements' text
  35. var optionTexts = [];
  36.  
  37. // iterate through all option elements
  38. $('#sel > option').each(function() {
  39. // get value/text and push it into respective array
  40. optionValues.push($(this).val());
  41. optionTexts.push($(this).text());
  42. });
  43.  
  44. // test with alert
  45. alert(optionValues);
  46. alert(optionTexts);
  47. });
  48.  
  49. var values = jQuery.map(jQuery("#select")[0].options, function(option)
  50. {
  51. return option.value;
  52. });
  53.  
  54. var texts = jQuery.map(jQuery("#select")[0].options, function(option)
  55. {
  56. return option.innerHTML;
  57. });
  58.  
  59. $("#CityLocal").autocompleteArray(
  60. MyBigArrayOfOptions,
  61. {
  62. delay:10,
  63. minChars:1,
  64. matchSubset:1,
  65. onItemSelect:selectItem,
  66. onFindValue:findValue,
  67. autoFill:true,
  68. maxItemsToShow:10
  69. }
  70. );
  71.  
  72. myFunction($("#my-select option"));
  73.  
  74. myFunction($("option", theSelect));
  75.  
  76. $("#CityLocal").autocompleteArray(
  77. $("option", theSelect),
  78. {
  79. delay:10,
  80. minChars:1,
  81. matchSubset:1,
  82. onItemSelect:selectItem,
  83. onFindValue:findValue,
  84. autoFill:true,
  85. maxItemsToShow:10
  86. }
  87. );
Add Comment
Please, Sign In to add comment