473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

document.getElementById issue in Firefox

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[i]){
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

Mar 9 '07 #1
3 14352
pa*******@gmail.com wrote:
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[i]){
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

Mar 9 '07 #2
Thanks Erwin... issue is resolved... oh that was bad. I did not
realize the mistake.....
Thanks once again....

Mar 9 '07 #3
pa*******@gmail.com wrote:
>
[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.
Mar 9 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: bradwiseathome | last post by:
I have code that works in IE 6 but does not work in FireFox 1.0.2, how can I change it so it works in both browsers? <html> <head> <script language="JavaScript" type="text/JavaScript">...
3
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
4
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
13
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the...
5
by: dmk | last post by:
Hi All, function getWindowSize() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight =...
2
by: Big Guy 60 | last post by:
I can get this code to work in IE but not in firefox. I have a site with 20 <div> item throughtout the site. All of the <div> tags have unique ids. I am using an ajax call to hit a "heartbeat"...
7
by: sj071 | last post by:
I'm little more than a novice when it comes to javascript, and this particular problem has been driving me mad for the past few days... The Problem: I have a javascript file that uses...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.