document.getElementById issue in Firefox

P

palak123i

Hi All,

I am using a javascript to submit a request using AJAX. Part of
javascript code as follows:

var favElement = document.getElementById('fav1');
alert(favElement);
for (var i = 0; i < userGroupArray.length; i++){
for (var j = 0; j < favElement.length; j++){
if(favElement.options[j].value == userGroupArray){
favElement.options[j].selected = true;
}
}
}

fav1 is a html select element with attribute multiple="true" (please
see snipet below)

<select class="" multiple size="4" name="fav1">
<option value="">-- select --</option>
<option value='10' >1100</option>
.....
</select>

In IE 6.0, alert(favElement) returns object properly and rest of the
code works fine...

In FireFox 1.5, alert(favElement) returns null...

In Netscape 7.0 , alert(favElement) does nothing

So the code is failing in Firefox and Netscape. Can anybody suggest,
whats wrong? document.getElementById does not work in Firefox/
Netscape?

Thanks in advance,
Palak
 
E

Erwin Moller

Hi All,

I am using a javascript to submit a request using AJAX. Part of
javascript code as follows:

var favElement = document.getElementById('fav1');
alert(favElement);
for (var i = 0; i < userGroupArray.length; i++){
for (var j = 0; j < favElement.length; j++){
if(favElement.options[j].value == userGroupArray){
favElement.options[j].selected = true;
}
}
}

fav1 is a html select element with attribute multiple="true" (please
see snipet below)

<select class="" multiple size="4" name="fav1">
<option value="">-- select --</option>
<option value='10' >1100</option>
.....
</select>

In IE 6.0, alert(favElement) returns object properly and rest of the
code works fine...

In FireFox 1.5, alert(favElement) returns null...

In Netscape 7.0 , alert(favElement) does nothing

So the code is failing in Firefox and Netscape. Can anybody suggest,
whats wrong? document.getElementById does not work in Firefox/
Netscape?

Thanks in advance,
Palak


Hi Palak,

I think you confuse name="" and id="".
The name="" is used to create name-value pairs for the receiving script, the
id="" is used to, well, create an id.
So just add id="fav1" and your code is correct.

Regards,
Erwin Moller
 
P

palak123i

Thanks Erwin... issue is resolved... oh that was bad. I did not
realize the mistake.....


Thanks once again....
 
T

The Magpie

[snip]
<select class="" multiple size="4" name="fav1">
<option value="">-- select --</option>
<option value='10' >1100</option>
.....
</select>

In IE 6.0, alert(favElement) returns object properly and rest of the
code works fine...
And that is MSIE doing it wrong because, as you can see, you do not
have an element with the ID "fav1".
In FireFox 1.5, alert(favElement) returns null...
And that is Firefox doing it *right* (it is not failing, the Microsoft
browser is). There is all the world of difference between a *name* and
an ID. If you look for an ID, you have to have one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top