diff options
Diffstat (limited to 'lib/js/urweb.js')
-rw-r--r-- | lib/js/urweb.js | 34 |
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; } |