[thelist] Internet explorer selection list counting bug?
Mohsen Saboorian
mohsens at gmail.com
Sat Sep 16 04:34:09 CDT 2006
You select your option after select creation (after the loop):
...
// if(i==2) {
// window.setTimeout(function() {alert(i); opt.selected = true;}, 0);
// }
sel.options[sel.options.length] = opt;
}
sel.options[2].selected = true;
On 9/16/06, ÕÅí|Îä <zhangweiwu at realss.com> wrote:
> Hello. I encounted this problem when I work for a website that require a
> <select> list being generated on-the-fly with javascript. I find it very
> difficult to set an option pre-selected by setting 'selected' of the
> option element.
>
> e.g. the following HTML source makes entry 'c' pre-selected on Firefox
> (expected), and make entry 'b' pre-selected on IE (surprise).
> (see http://weiwu.freeshell.org/ie_selection_counting_bug.html )
>
> How do I write javascript to pre-select dynamically-generated-options
> that work for both IE and Firefox?
>
> <html>
> <body>
> <form>
> <select id="sel">
> </select>
> </form>
> <script type="text/javascript">
> var opts = ['a','b','c','d'];
> var sel = document.getElementById("sel");
> for(var i=0; i<opts.length; i++) {
> //var opt = new Option(opts[i],i,false,i==2?true:false);
> var opt = document.createElement("option");
> opt.text = opts[i];
> opt.value = i;
> if(i==2)
> opt.selected = true;
> sel.options[sel.options.length] = opt;
> }
> </script>
> </body>
> </html>
>
>
>
> --
>
> * * Please support the community that supports you. * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>
>
More information about the thelist
mailing list