By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

code that not work on IE

P: n/a

this code not work on IE; on firefox is all ok;
IE not allow to use array[i][0],
that, in one array simple, is the first word of every element
var my_select=document.getElementById("name_select");
var hidden_a= new Array("book","book","1","table","window");

var xxx=0;
for (var i = 0; i <hidden_a.length; i++)
{ my_select.options[xxx++]=new Option(hidden_a[i][0]);}

on firefox the result is:
b
b
1
t
w
Sep 17 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
artev wrote on 17 sep 2006 in comp.lang.javascript:
this code not work on IE; on firefox is all ok;
IE not allow to use array[i][0],
that, in one array simple, is the first word of every element
var my_select=document.getElementById("name_select");
var hidden_a= new Array("book","book","1","table","window");

var xxx=0;
for (var i = 0; i <hidden_a.length; i++)
{ my_select.options[xxx++]=new Option(hidden_a[i][0]);}
<select id='name_select'>
</select>

<script type='text/javascript'>

var my_select=document.getElementById("name_select");
var hidden_a= ["book","book","1","table","window"];

for (var i = 0; i <hidden_a.length; i++) {
var opt = document.createElement('OPTION');
opt.value = i; // if you wish
opt.text = hidden_a[i].substr(0,1);
my_select.options.add(opt, i);
}

</script>

Read:
<http://www.quirksmode.org/js/options.html>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 17 '06 #2

P: n/a
Evertjan. wrote on 17 sep 2006 in comp.lang.javascript:
artev wrote on 17 sep 2006 in comp.lang.javascript:
>this code not work on IE; on firefox is all ok;
IE not allow to use array[i][0],
that, in one array simple, is the first word of every element
var my_select=document.getElementById("name_select");
var hidden_a= new Array("book","book","1","table","window");

var xxx=0;
for (var i = 0; i <hidden_a.length; i++)
{ my_select.options[xxx++]=new Option(hidden_a[i][0]);}

<select id='name_select'>
</select>

<script type='text/javascript'>

var my_select=document.getElementById("name_select");
var hidden_a= ["book","book","1","table","window"];

for (var i = 0; i <hidden_a.length; i++) {
var opt = document.createElement('OPTION');
opt.value = i; // if you wish
opt.text = hidden_a[i].substr(0,1);
my_select.options.add(opt, i);
}

</script>

Read:
<http://www.quirksmode.org/js/options.html>
Your code also works in IE[6], when using:

.... = new Option(hidden_a[i].substr(0,1));

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 17 '06 #3

P: n/a
artev wrote:
this code not work on IE; on firefox is all ok;
IE not allow to use array[i][0],
that, in one array simple, is the first word of every
element
var my_select=document.getElementById("name_select");
var hidden_a= new Array("book","book","1","table","window");

var xxx=0;
for (var i = 0; i <hidden_a.length; i++)
{ my_select.options[xxx++]=new Option(hidden_a[i][0]);}

on firefox the result is:
b
b
1
t
w
Being able to access the characters in a string by 'array index' with
square bracket notation is a JavaScritp(tm) extension to ECMAScritp that
is not featured in any other ECMA 262 3rd edition implementations. In
place of arayOfStrings[i][n] - use arrayOfStrings[i].charAt(n) -, as
that will work in all implementations.

Richard.
Sep 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.