473,392 Members | 1,462 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,392 software developers and data experts.

GetElementById vs. IE7

Hello all,

I have some simple JavaScript code that changes an image based on some user action (i.e. pushing a button).
I sniff the broiwsers and, in case of IE5+, I use GetElementById and then change the object.src, pointing to the proper gif or jpg.
The code is:

if ( document.getElementById ) // IE5+ & Gecko
{
if ( document.getElementById( id ).innerHTML != null )
{
document.getElementById( id ).innerHTML.src = url;
}
}
else if ( document.getElementById ) // IE5+ & Gecko
{
if ( document.getElementById( id ) != null )
{
document.getElementById( id ).src = url;
}
}
else if (document.all) // IE4
{
if ( document.all[ id ] != null )
{
document.all[ id ].src = url;
}
}
else // Netscape 4
{
if ( document.images[ id ] != null )
{
document.images[ id ].src = url;
}
}

Very basic JavaScript... should it be...
In fact, it works fine with IE5 or IE6 and Netscape, but does not work with IE7.
Is there anything regarding GetElementById and IE7 ?
Or is my piece of script wrong ?

Pelase, help... :-|
May 7 '07 #1
3 5579
Hello all,

I have some simple JavaScript code that changes an image based on some user action (i.e. pushing a button).
I sniff the broiwsers and, in case of IE5+, I use GetElementById and then change the object.src, pointing to the proper gif or jpg (selected by the "url" variable, previously assigned according to the user action, e.g. button on/off).
The code is:

if ( document.getElementById ) // IE5+ & Gecko
{
if ( document.getElementById( id ).innerHTML != null )
{
document.getElementById( id ).innerHTML.src = url;
}
}
else if ( document.getElementById ) // IE5+ & Gecko
{
if ( document.getElementById( id ) != null )
{
document.getElementById( id ).src = url;
}
}
else if (document.all) // IE4
{
if ( document.all[ id ] != null )
{
document.all[ id ].src = url;
}
}
else // Netscape 4
{
if ( document.images[ id ] != null )
{
document.images[ id ].src = url;
}
}

Very basic JavaScript... should it be...
In fact, it works fine with IE5 or IE6 and Netscape, but does not work with IE7.
Is there anything regarding GetElementById and IE7 ?
Or is my piece of script wrong ?

Please, help... :-|
May 7 '07 #2
r035198x
13,262 8TB
Hello all,

I have some simple JavaScript code that changes an image based on some user action (i.e. pushing a button).
I sniff the broiwsers and, in case of IE5+, I use GetElementById and then change the object.src, pointing to the proper gif or jpg.
The code is:

if ( document.getElementById ) // IE5+ & Gecko
{
if ( document.getElementById( id ).innerHTML != null )
{
document.getElementById( id ).innerHTML.src = url;
}
}
else if ( document.getElementById ) // IE5+ & Gecko
{
if ( document.getElementById( id ) != null )
{
document.getElementById( id ).src = url;
}
}
else if (document.all) // IE4
{
if ( document.all[ id ] != null )
{
document.all[ id ].src = url;
}
}
else // Netscape 4
{
if ( document.images[ id ] != null )
{
document.images[ id ].src = url;
}
}

Very basic JavaScript... should it be...
In fact, it works fine with IE5 or IE6 and Netscape, but does not work with IE7.
Is there anything regarding GetElementById and IE7 ?
Or is my piece of script wrong ?

Pelase, help... :-|
Please do not double post.

Threads merged
May 7 '07 #3
acoder
16,027 Expert Mod 8TB
You can't have
Expand|Select|Wrap|Line Numbers
  1. document.getElementById( id ).innerHTML.src;
Get rid of that 'if' code block.

In any case, if the first code block is executed, it's not going to execute the second one which checks for the same thing.
May 7 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
12
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with...
4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
7
by: PaulB | last post by:
Good Morning everybody, I'm trying to adapt a tutorial script that will handle the behaviour of an "Expanding/Contracting" site-navigation menu. The code that seems to handle the expansion and...
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...
1
by: Andre Ranieri | last post by:
Hello, I'm trying to set up an ASP.NET 2.0 form where the user enters values in WebControls.TextBoxes for amount owing, interest and late fees and a JavaScript function totals the three values...
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: jhappeal | last post by:
I do not know Javascript that well so I might be going about this the wrong way. Any help would be appreciated. This function attempts to hide the options inside of the optgroup tag of the second...
1
by: vikD | last post by:
Hello, I'm really bad at javascript but I managed to get the code below to work in IE but firefox gives this error... Error: document.getElementById.formall is undefined Basically use the...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
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...

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.