Mercurial > urweb
comparison 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 |
comparison
equal
deleted
inserted
replaced
1478:a10d080123ec | 1479:f561025bb68e |
---|---|
481 x.onkeyup = function() { sv(s, x.value) }; | 481 x.onkeyup = function() { sv(s, x.value) }; |
482 | 482 |
483 return x; | 483 return x; |
484 } | 484 } |
485 | 485 |
486 function selectValue(x) { | |
487 if (x.options.length == 0) | |
488 return ""; | |
489 else | |
490 return x.options[x.selectedIndex].value; | |
491 } | |
492 | |
493 function setSelectValue(x, v) { | |
494 for (var i = 0; i < x.options.length; ++i) { | |
495 if(x.options[i].value == v) { | |
496 x.selectedIndex = i; | |
497 return; | |
498 } | |
499 } | |
500 } | |
501 | |
486 function sel(s, content) { | 502 function sel(s, content) { |
487 var dummy = document.createElement("span"); | 503 var dummy = document.createElement("span"); |
488 dummy.innerHTML = "<select>" + content + "</select>"; | 504 dummy.innerHTML = "<select>" + content + "</select>"; |
489 var x = input(dummy.firstChild, s, function(x) { return function(v) { if (x.value != v) x.value = v; }; }); | 505 var x = input(dummy.firstChild, s, function(x) { return function(v) { if (selectValue(x) != v) setSelectValue(x, v); }; }); |
490 x.value = s.data; | 506 |
491 if (x.value != s.data) | 507 for (var i = 0; i < x.options.length; ++i) { |
492 sv(s, x.value); | 508 if (x.options[i].value == "") |
493 x.onchange = function() { sv(s, x.value) }; | 509 x.options[i].value = x.options[i].text; |
510 else | |
511 x.options[i].value = x.options[i].value.substring(1); | |
512 } | |
513 | |
514 setSelectValue(x, s.data); | |
515 if (selectValue(x) != s.data) | |
516 sv(s, selectValue(x)); | |
517 x.onchange = function() { sv(s, selectValue(x)) }; | |
494 | 518 |
495 return x; | 519 return x; |
496 } | 520 } |
497 | 521 |
498 function chk(s) { | 522 function chk(s) { |