Mercurial > urweb
diff lib/js/urweb.js @ 1479:f561025bb68e
Workaround for old IE handling of <option> with no 'value' attribute
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 26 Jun 2011 19:45:21 -0400 |
parents | 607657eb2865 |
children | ae7547789c73 |
line wrap: on
line diff
--- a/lib/js/urweb.js Fri Jun 24 13:50:59 2011 -0400 +++ b/lib/js/urweb.js Sun Jun 26 19:45:21 2011 -0400 @@ -483,14 +483,38 @@ 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; }