summaryrefslogtreecommitdiffstats
path: root/js/util.js
diff options
context:
space:
mode:
authorMax Kanat-Alexander <mkanat@bugzilla.org>2011-08-09 23:19:43 +0200
committerMax Kanat-Alexander <mkanat@bugzilla.org>2011-08-09 23:19:43 +0200
commit80c6d150b42ae5d9ba7464c5e20023cc90388259 (patch)
tree77df9794d444fbc861f53aa0240128a53f9d6467 /js/util.js
parent93175c689f0349d879b3dfca5bd0236c19b73855 (diff)
downloadbugzilla-80c6d150b42ae5d9ba7464c5e20023cc90388259.tar.gz
bugzilla-80c6d150b42ae5d9ba7464c5e20023cc90388259.tar.xz
Bug 636416: Use the standard value-controller javascript to control the
drop-down fields on the Advanced Search page. r=glob, a=mkanat
Diffstat (limited to 'js/util.js')
-rw-r--r--js/util.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/js/util.js b/js/util.js
index 6dcabbbc9..56649ac66 100644
--- a/js/util.js
+++ b/js/util.js
@@ -220,6 +220,34 @@ function bz_valueSelected(aSelect, aValue) {
}
/**
+ * Returns all Option elements that are selected in a <select>,
+ * as an array. Returns an empty array if nothing is selected.
+ *
+ * @param aSelect The select you want the selected values of.
+ */
+function bz_selectedOptions(aSelect) {
+ // HTML 5
+ if (aSelect.selectedOptions) {
+ return aSelect.selectedOptions;
+ }
+
+ var start_at = aSelect.selectedIndex;
+ if (start_at == -1) return [];
+ var first_selected = aSelect.options[start_at];
+ if (!aSelect.multiple) return first_selected;
+ // selectedIndex is specified as being the "first selected item",
+ // so we can start from there.
+ var selected = [first_selected];
+ var options_length = aSelect.options.length;
+ // We start after first_selected
+ for (var i = start_at + 1; i < options_length; i++) {
+ var this_option = aSelect.options[i];
+ if (this_option.selected) selected.push(this_option);
+ }
+ return selected;
+}
+
+/**
* Tells you where (what index) in a <select> a particular option is.
* Returns -1 if the value is not in the <select>
*