summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2011-06-26 19:45:21 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2011-06-26 19:45:21 -0400
commit5c9c4fd88a74fcd73d8381dff76e1e15cd9b31c6 (patch)
treea1ebb9f30076e2de19a2c0f17273b3df7ee93ba9 /lib
parent57e22bb49145d0c4da64b8ff76540b286c55a448 (diff)
Workaround for old IE handling of <option> with no 'value' attribute
Diffstat (limited to 'lib')
-rw-r--r--lib/js/urweb.js34
1 files changed, 29 insertions, 5 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index a3ab6fde..017ff747 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -483,14 +483,38 @@ function inp(s, name) {
return x;
}
+function selectValue(x) {
+ if (x.options.length == 0)
+ return "";
+ else
+ return x.options[x.selectedIndex].value;
+}
+
+function setSelectValue(x, v) {
+ for (var i = 0; i < x.options.length; ++i) {
+ if(x.options[i].value == v) {
+ x.selectedIndex = i;
+ return;
+ }
+ }
+}
+
function sel(s, content) {
var dummy = document.createElement("span");
dummy.innerHTML = "<select>" + content + "</select>";
- var x = input(dummy.firstChild, s, function(x) { return function(v) { if (x.value != v) x.value = v; }; });
- x.value = s.data;
- if (x.value != s.data)
- sv(s, x.value);
- x.onchange = function() { sv(s, x.value) };
+ var x = input(dummy.firstChild, s, function(x) { return function(v) { if (selectValue(x) != v) setSelectValue(x, v); }; });
+
+ for (var i = 0; i < x.options.length; ++i) {
+ if (x.options[i].value == "")
+ x.options[i].value = x.options[i].text;
+ else
+ x.options[i].value = x.options[i].value.substring(1);
+ }
+
+ setSelectValue(x, s.data);
+ if (selectValue(x) != s.data)
+ sv(s, selectValue(x));
+ x.onchange = function() { sv(s, selectValue(x)) };
return x;
}