473,796 Members | 2,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getElementbyId Firefox v IE

My code works fine in IE but not FF.

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="test. aspx.cs"
Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
<script>
function window_onload()
{
runTime();
setInterval(run Time, 60000);

// todo: apply png transparent style for ie < 7.0
//
filter:progid:D XImageTransform .Microsoft.Alph aImageLoader(sr c=Images/WebDesktopIconR ound.png)
}

function runTime()
{
var rightPart = document.getEle mentById("dvRig htTemplate");
var time = new Date();
var hour = time.getHours() ;
var minute = time.getMinutes ();
var second = time.getSeconds ();
var temp = "";
temp += ((hour < 10) ? "0" : "")+ hour +((minute < 10) ?
":0" : ":") + minute;
rightPart.inner Text = temp;
}

</script>
</head>

<body id="body" runat="server" o>
<form id="form1" runat="server">
<div>
<div id="dvRightTemp late" align="right" style="padding-right:
10px; font-size: 8pt;
width: 80px; font-family: Tahoma; color:black">
<!-- Notes: Always specify width attribute for
proper rendering in Mozilla -->
00:00</div>
</div>
</form>

</body>
</html>

Jan 25 '06 #1
6 28450
bne
zippy wrote:
My code works fine in IE but not FF.

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="test. aspx.cs"
Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
<script>
function window_onload()
{
runTime();
setInterval(run Time, 60000);

// todo: apply png transparent style for ie < 7.0
//
filter:progid:D XImageTransform .Microsoft.Alph aImageLoader(sr c=Images/WebDesktopIconR ound.png)
}

function runTime()
{
var rightPart = document.getEle mentById("dvRig htTemplate");
var time = new Date();
var hour = time.getHours() ;
var minute = time.getMinutes ();
var second = time.getSeconds ();
var temp = "";
temp += ((hour < 10) ? "0" : "")+ hour +((minute < 10) ?
":0" : ":") + minute;
rightPart.inner Text = temp;
}

</script>
</head>

<body id="body" runat="server" o>
<form id="form1" runat="server">
<div>
<div id="dvRightTemp late" align="right" style="padding-right:
10px; font-size: 8pt;
width: 80px; font-family: Tahoma; color:black">
<!-- Notes: Always specify width attribute for
proper rendering in Mozilla -->
00:00</div>
</div>
</form>

</body>
</html>


Hi

innerText is specific to the IE DOM use innerHTML instead.

ben

Jan 25 '06 #2
Thanks! How annoying!

Jan 25 '06 #3
In article <11************ *********@f14g2 000cwb.googlegr oups.com>,
"zippy" <jo************ **@gmail.com> wrote:
Thanks! How annoying!


actually the reference I have says the neither are DOM, but both IE 4.
And as I am told ".value" is often a supported shortcut but not a real
property?

text in a div has to be scooped out. elem.firstChild .data is it in the
simple case. What a pain!
If you control the HTML that is being looked at you can make sure
there are no subElements, but you might imagine how there could be more
nested in a div.

sorry, don't shoot the msngr. I am just learning this myself.

also, a search in the newsgroup showed that document.getEle mentById()
is not always supported. I don't know how far abck that is going. But
the compatability code that I coped is this:
// getElementById Special to handle quirky browsers
// most will use getElementById( )
function getElementById_ s(id){
var obj = null;
if(document.get ElementById){
/* Prefer the widely supported W3C DOM method, if
available:-
*/
obj = document.getEle mentById(id);
}else if(document.all ){
/* Branch to use document.all on document.all only
browsers. Requires that IDs are unique to the page
and do not coincide with NAME attributes on other
elements:-
*/
obj = document.all[id];
}
/* If no appropriate element retrieval mechanism exists on
this browser this function always returns null:-
*/
return obj;
}
Jan 26 '06 #4
bne wrote:
[...]

innerText is specific to the IE DOM use innerHTML instead.

The DOM equivalent to IE's innerText property is textContent. Since
it's part of DOM 3, not all browsers support it but newer Gecko browsers
do (and probably others). A reasonable emulation is:

function getTextContent( el)
{
if (el.textContent ) return el.textContent;
if (el.innerText) return (el.innerText);

var cNode, cNodes = el.childNodes;
var txt = '';
for (var i=0, len=cNodes.leng th; i<len; ++i){
cNode = cNodes[i];
if (1 == cNode.nodeType) {
txt += getTextContent( cNode);
}
if (3 == cNode.nodeType) {
txt += cNode.data;
}
}
return txt;
}
Newlines may be inserted inconsistently in different browsers. Support
for other node types may be required.
--
Rob
Jan 27 '06 #5
one man army wrote:
[...]
also, a search in the newsgroup showed that document.getEle mentById()
is not always supported. I don't know how far abck that is going. But


The FAQ offers a dynWrite function, but there is an alternative offered
here:

<URL: http://www.jibbering.com/faq/faq_not...e.html#alDynWr >
I like option 3, it is probably suitable in most cases - but read the
accompanying notes.
--
Rob
Jan 27 '06 #6
RobG wrote:
bne wrote:
[...]
innerText is specific to the IE DOM use innerHTML instead.
The DOM equivalent to IE's innerText property is textContent.


Unfortunately, I do not think it is. IE trims whitespace text nodes in its
DOM, so it is likely that it also trims it from the value of `innerText'.
I am not sure about that, though, since I have not IE to test with.
Since it's part of DOM 3, not all browsers support it but newer Gecko
browsers do (and probably others). A reasonable emulation is:

function getTextContent( el)
{
if (el.textContent ) return el.textContent;
if (el.innerText) return (el.innerText);
[...]


Neither will return if the element content is (considered) empty, and so
force the following code to execute. Evaluating the `typeof' operation is
more reliable here.
PointedEars
Feb 15 '06 #7

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

Similar topics

10
1910
by: Dave Hammond | last post by:
Hi All, The following code works in IE but not Firefox. IE produces the expected "this is more text!" output, but Firefox produces "no more text". Any ideas why? <BODY> <FORM> <INPUT TYPE=HIDDEN NAME="moreText" VALUE="<PRE>This is more text!</PRE>">
1
3427
by: Muffinman | last post by:
Howdy, I've got here a sample of my function which is supposed to fade a certain piece of text to another colour. This line is then located in a for loop and it works pretty well in IE 6. However, in Firefox, and thus I assume it will be the same in Netscape and Mozilla, it gives a problem with the: getElementById('main_txt'). Due to that in setTimeout("",) it requires the "" signes and thus I can not use the same ones in the getElement...
5
31227
by: Derek Erb | last post by:
I am banging my head against the wall with this one. The following code snippets work perfectly fine in MSIE6. But produce an error in Firefox and do not work at all. BROWSER.HTM <HTML> .... <div class="Abb"> <h2 id="ABTit">BROWSER</h2> </div>
3
9277
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) {
5
4342
by: Andrea | last post by:
I am trying to alter css using javascript as well as use the innerHTML function. I have pasted below 3 forms that access getElementById in slightly different ways (I wanted to rule out that it was the method.) All 3 work fine on IE but only work momentarily on Firefox. For example, one form has text that changes from red to black when the user clicks the button. In IE it changes. In Firefox it changes for a split second then goes back...
4
2667
by: the other john | last post by:
I came across a third party script I want to learn how to configure as well as learn more dhtml in the doing. I'm not much of a JS guy yet but I'm working on it. This script works fine in IE6 but is a dead fish in FireFox. There is no support offered on the site where it came from. I'd really appreciate help with this as it will not only to get it working but to learn how it all works so I can add it to my repertoire. Thanks!
13
4967
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:
8
3146
by: cyqotiq | last post by:
First, let me state that this is not necessarily a Firefox problem, as I haven't fully tested in IE just yet. Second, let me state that this is not the typical "getElementById not working Firefox" post. Third, there are pieces of this code that I am not at liberty to display, change, discuss, or re-implement. As far as this question is concerned, this means that (1) I cannot use 3rd party libraries, which is why I've implemented my own...
3
2064
by: GarryJones | last post by:
The following works in MSIE but not firefox. I suspect it has something to do with the fact that the element I am trying to access is not the "tid" which is the name of the DIV that is passed to this javascript. The function is a "show/hide" for a form. I want to ensure that any possible previously entered value is cleared so the user starts with an empty field with focus. I have tried to ways, with naming and getElementById but in...
1
2240
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 script to update the display to the user depending on what they choose (qty, options, shipping etc.) I'm sure it's simple but I could really use a hand. Thanks!!
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10467
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...
1
10201
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
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
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
7558
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
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3744
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.