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

children["id"].innerText - does not work with netscape but with explorer

I have a function that works with explorer but not with netscape.
The problem is the function at line 5.
1 fSetSelectedDay(myElement){
2 /*
3 ...
4 */
5 var elementText = eval(myElement.children["calDateText"].innerText);
6 /*
7 ...
8 */
9 }
10 <!-- ... -->
11 <td id=calCell onclick='fSetSelectedDay(this)'>
12 <font id='calDateText' onclick='fSetSelectedDay(this)'>
13 <script> myMonth[w][d] </script>
14 </font>
15 </td>
16 <!-- ... -->
I need some support for this.
Thank you very much.
Jul 23 '05 #1
13 3751
Julia Peterwitz wrote:
I have a function that works with explorer but not with netscape.
The problem is the function at line 5.
1 fSetSelectedDay(myElement){
2 /*
3 ...
4 */
5 var elementText = eval(myElement.children["calDateText"].innerText);


..innerText is IE only, and as such is not going to work in NS. use
innerHTML instead.

eval is not needed there:

var elementText =
document.getElementById(myElement).children('calDa teText').innerHTML;

the [ ] are also an IE-ism.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #2
On Wed, 05 May 2004 06:41:28 -0400, Randy Webb <hi************@aol.com>
wrote:
Julia Peterwitz wrote:
I have a function that works with explorer but not with netscape.
The problem is the function at line 5.
1 fSetSelectedDay(myElement){
2 /*
3 ...
4 */
5 var elementText = eval(myElement.children["calDateText"].innerText);
.innerText is IE only, and as such is not going to work in NS. use
innerHTML instead.

eval is not needed there:


Agreed, however...
var elementText =
document.getElementById(myElement).children('calDa teText').innerHTML;


....there are two problems with this line:

1) If you look at the OP's HTML, you'll see that myElement is a
reference to the element, not an id.
2) The children property is
a) a collection, so the brackets were correct,
b) also a Microsoft-ism.

Perhaps

var elementText = myElement.childNodes[ 'calDateText' ].innerHTML;

would be better (preferably with feature detection)?

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #3
myElement.childNodes[ 'calDateText' ].innerHTML;
is also not working
(it neither works in explorer nor in netscape)

any other proposals for netscape??

solution for explorer again:
myElement.children["calDateText"].innerText;

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4
On 05 May 2004 16:37:14 GMT, julia peterwitz <pi***@gmx.de> wrote:
myElement.childNodes[ 'calDateText' ].innerHTML;
is also not working
(it neither works in explorer nor in netscape)

any other proposals for netscape??


Oops. I assumed that childNodes was a standard collection that could be
indexed by name/id as well as ordinal. However, I just thought that
'calDateText' is an id, so why don't you just use

document.getElementById( 'calDateText' ).innerHTML

?

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #5
pi***@gmx.de (Julia Peterwitz) writes:
I have a function that works with explorer but not with netscape.
The problem is the function at line 5.
You don't say which Netscape. If it's Netscape 4, your options are
very limited. If it's Netscape 6+, i.e., based on Mozilla, then
you can pretty much fly :) I'll assume Netscape 6+.
5 var elementText = eval(myElement.children["calDateText"].innerText);
I see three problems:
- innerText is IE only.
- children is IE only.
- eval is evil.

There are different options, depending on how standards compliant you
want to be. I'll go for full compliance with the DOM specification
(i.e., avoiding innerHTML).

A version that collects the string content of the calcDateText element
(not recursively, so don't put the text to find inside tags).
---
var span = document.getElementById("calcDateText");
var elementText = "";
for(var chld = span.firstChild; chld; chdl=chld.nextSibling) {
if (chld.nodeType == 3) { // text node
elementText += chld.nodeValue;
}
}
---
Or, change the first line to:
---
var span = myElement.getElementsByTagName("span")[0];
---
(Notice that I use "span" instead of "font" as commented later)
11 <td id=calCell onclick='fSetSelectedDay(this)'>
12 <font id='calDateText' onclick='fSetSelectedDay(this)'>
The font tag is deprecated and you are not using any of its specific
attributes anyway. Change it to a <span> instead, that is just what
you need: a meaningless wrapper.
13 <script> myMonth[w][d] </script>
The type attribute is required on script tags, so:
---
<script type="text/javascript">
---
Do you mean to document.write the value?
---
document.write(myMonth[w][d]));
---
Where are "w" and "d" calculated? (Meaning Week and Day?)
14 </font>

</span>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #6
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote in message news:<hd**********@hotpop.com>...
pi***@gmx.de (Julia Peterwitz) writes:
I have a function that works with explorer but not with netscape.
The problem is the function at line 5.
You don't say which Netscape. If it's Netscape 4, your options are
very limited. If it's Netscape 6+, i.e., based on Mozilla, then
you can pretty much fly :) I'll assume Netscape 6+.


yes, I thought about netscape 6+
5 var elementText = eval(myElement.children["calDateText"].innerText);
I see three problems:
- innerText is IE only.
- children is IE only.
- eval is evil.

There are different options, depending on how standards compliant you
want to be. I'll go for full compliance with the DOM specification
(i.e., avoiding innerHTML).

A version that collects the string content of the calcDateText element
(not recursively, so don't put the text to find inside tags).
---
var font= myElement.getElementsByTagName("font");
var elementText = "";


until here it works.
but the following doesn't start.
and I don't know why.
but there is no error message.
for(var chld = font.firstChild; chld; chdl=chld.nextSibling) {
if (chld.nodeType == 3) { // text node
elementText += chld.nodeValue;
}
}
---
11 <td id=calCell onclick='fSetSelectedDay(this)'>
12 <font id='calDateText' onclick='fSetSelectedDay(this)'>
The font tag is deprecated and you are not using any of its specific
attributes anyway. Change it to a <span> instead, that is just what
you need: a meaningless wrapper.


I removed the irrelevant attributes.
so I will use <font> further on.
13 <script> myMonth[w][d] </script>
The type attribute is required on script tags, so:
---
<script type="text/javascript">
---
Do you mean to document.write the value?
---
document.write(myMonth[w][d]));


sorry I forgot to put the document.write around

13 <script> document.write(myMonth[w][d]); </script>

this function notes the days of the months, but this is irrelevant for
the problem. isn't it?
---
Where are "w" and "d" calculated? (Meaning Week and Day?)
14 </font>

</span>

/L

Jul 23 '05 #7
pi***@gmx.de (Julia Peterwitz) writes:
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote in message news:<hd**********@hotpop.com>...
var font= myElement.getElementsByTagName("font");
var elementText = "";


until here it works.
but the following doesn't start.
and I don't know why.
but there is no error message.
for(var chld = font.firstChild; chld; chdl=chld.nextSibling) {


Damn! :(
That would be the typo: ^^^^ shoud be chld.

That would mean that the loop goes on forever ... doing nothing.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #8
/*
....
*/

alert("1");
var font = myElement.getElementsByTagName("font");
alert("2");
var elementText = "";
alert("3");
for(var chld = font.firstChild; chld; chld=chld.nextSibling) {
alert("4");
if (chld.nodeType == 3) { // text node
elementText += chld.nodeValue;
}

/*
....
*/

when I start this I'll get the alert's 1,2,3 but the alert 4 doesn't start.
so I think there is something wrong.
but I don't know what.
Jul 23 '05 #9
Michael Winter <M.******@blueyonder.co.invalid> wrote in message news:<op**************@news-text.blueyonder.co.uk>...
On 05 May 2004 16:37:14 GMT, julia peterwitz <pi***@gmx.de> wrote:
myElement.childNodes[ 'calDateText' ].innerHTML;
is also not working
(it neither works in explorer nor in netscape)

any other proposals for netscape??


Oops. I assumed that childNodes was a standard collection that could be
indexed by name/id as well as ordinal. However, I just thought that
'calDateText' is an id, so why don't you just use

document.getElementById( 'calDateText' ).innerHTML

?

Mike

elementText = document.getElementById('calDateText').innerHTML;
alert(elementText);

good idea, but elementText is "".
do you know why?
Jul 23 '05 #10
On 7 May 2004 01:44:12 -0700, Julia Peterwitz wrote:
elementText = document.getElementById('calDateText').innerHTML;
alert(elementText); good idea, but elementText is "".
do you know why?


Try something like that:

<script type="text/javascript">
function getInnerText(el){
return
el.innerHTML.replace(/(<script[^>]*?>.*?<\/script>)|[\r\n]/gi,"").replace(/<[\/\!]*?[^<>]*?>/g,"");
}

function fSetSelectedDay(el){
alert(">"+getInnerText(el)+"<");
}
</script>

<font id='calDateText'
onclick='fSetSelectedDay(this)'><script>document.w rite('some text,<br />
maybe with <strong>tags</strong>');</script></font>

I hope it helps.
--
C'ya,
ZER0 :: coder.gfxer.webDesigner();

Il computer e' una macchina progettata per velocizzare e automatizzare
gli errori.
Jul 23 '05 #11
On 7 May 2004 01:44:12 -0700, Julia Peterwitz <pi***@gmx.de> wrote:

[snip]
elementText = document.getElementById('calDateText').innerHTML;
alert(elementText);

good idea, but elementText is "".
do you know why?


Not a clue. Can you post a complete sample (preferably a URL)?

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #12
Michael Winter <M.******@blueyonder.co.invalid> wrote in message news:<op**************@news-text.blueyonder.co.uk>...
On 7 May 2004 01:44:12 -0700, Julia Peterwitz <pi***@gmx.de> wrote:

[snip]
elementText = document.getElementById('calDateText').innerHTML;
alert(elementText);

good idea, but elementText is "".
do you know why?


Not a clue. Can you post a complete sample (preferably a URL)?

Mike


http://www.fligo.de/main/calender.js
is the url for the script

http://www.fligo.de/main/lastminute.php
is the url for the page
Jul 23 '05 #13
Julia Peterwitz wrote:
alert("1");
var font = myElement.getElementsByTagName("font");
alert("2");
var elementText = "";
alert("3");
for(var chld = font.firstChild; chld; chld=chld.nextSibling) { ^ alert("4");
if (chld.nodeType == 3) { // text node ^ elementText += chld.nodeValue;
} ^ /*
...
*/

when I start this I'll get the alert's 1,2,3 but the alert 4 doesn't start.
so I think there is something wrong.
but I don't know what.


Looks like there is a closing brace missing. Does the JavaScript
Console tell you anything? If yes, what does it say?
PointedEars
Jul 23 '05 #14

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

Similar topics

4
by: kaeli | last post by:
All, I've been unable to find out if javascript supports for (var e in obj) type of looping syntax. Does it? If so, is this for DOM browsers only? TIA! --
0
by: Bruce | last post by:
I have three tables in SQL serve tblareas (w/autoincrement ID tblprograms (w/autoincrement ID tblphases (w/autoincrement ID I've build cascading relation from tblareas <one-many> tblprograms...
4
by: Robin Tucker | last post by:
Hi, I'm currently implementing a database with a tree structure in a table. The nodes in the tree are stored as records with a column called "Parent". The root of the tree has a "NULL" parent....
7
by: GfxGuy | last post by:
I've seen this problem posted a million times, but I've read through all of them and can't figure out what I'm doing wrong. Simple example (this is the whole file, no editing): ---------- ...
19
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
1
by: John Beard | last post by:
I downloaded the attached code from MS. It flips on the "User Cannot Change Password" on a user in AD and works great from a console or windows app, but when put into an ASP.NET app I get a "The...
3
by: ivanov.alexei | last post by:
It's my first post and first DB application. Environment: MFC DAO, MS Access database I want to have several tables which have links to the fields to other tables. The following example explains...
9
by: Tristán White | last post by:
Hi I am very new to PHP - actually, this is my second day at it, as I've only recently started a new job last week. We're a charity. I have a "No input file selected" problem. A Google search...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.