473,806 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.getEle mentById 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.getEle mentById('fav1' );
alert(favElemen t);
for (var i = 0; i < userGroupArray. length; i++){
for (var j = 0; j < favElement.leng th; j++){
if(favElement.o ptions[j].value == userGroupArray[i]){
favElement.opti ons[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(favElemen t) returns object properly and rest of the
code works fine...

In FireFox 1.5, alert(favElemen t) returns null...

In Netscape 7.0 , alert(favElemen t) does nothing

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

Thanks in advance,
Palak

Mar 9 '07 #1
3 14376
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.getEle mentById('fav1' );
alert(favElemen t);
for (var i = 0; i < userGroupArray. length; i++){
for (var j = 0; j < favElement.leng th; j++){
if(favElement.o ptions[j].value == userGroupArray[i]){
favElement.opti ons[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(favElemen t) returns object properly and rest of the
code works fine...

In FireFox 1.5, alert(favElemen t) returns null...

In Netscape 7.0 , alert(favElemen t) does nothing

So the code is failing in Firefox and Netscape. Can anybody suggest,
whats wrong? document.getEle mentById 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(favElemen t) 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(favElemen t) 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
1834
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"> function AttributeSelected() { var selectVal = document.forms.elements.options;
3
9280
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 work on FireFox or Netscape. What could be wrong? The function: function setActiveTab(tabNo) {
136
9468
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 code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
4
2647
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 iframe's src property. Being that IE does not follow standard and considers an id, name, etc as a qualifying identifier for the document.getElementById object, I double checked to make sure that there's only one instance of id = "servif" and I never use...
13
4970
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 internet. When I run Firebug on it, it says: document.getElementById("TICKER") has no properties TICKER_CONTENT = document.getElementById("TICKER").innerHTML; Here is the complete script:
5
7498
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 = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
2
1610
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" page the returns a list of id names that I need to update the DIV contents. Once the heartbeat runs this function is called. function updateusage()
7
8969
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 document.write to send output to the browser. This javascript file contains some html code and another script tag. The execution order in Internet Explorer (6&7) appears to be different than that of browsers such as FireFox. Example:
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10364
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10370
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5545
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.