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

DOM Navigation in IE


I have a problem navigating a form in a table in IE using
the DOM. I can do what I want in Firefox, but not in IE.
The rest of my question and information is embedded
in the following code. Sorry, I don't have a web page to
publish it in.

I have tried to make it so it will copy and paste OK.

<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title> Clone Puzzle </title>

<script type="text/javascript">
function reportKids(thing,txt) {
var f = thing.childNodes;
var preTxt = '';
var msg = txt;
for (var i=0; i<f.length; ++i){
msg += '\nChild ' + i + ' is a ' + f[i];
var g = f[i].childNodes;
for (var j=0; j<g.length; ++j){
preTxt = '\nChild ' + i + ', subChild '
msg += preTxt +
j + ' is a ' + g[j] +
' of type ' + g[j].nodeType;
if (g.childNodes){
msg += '\n.....More kids this node';
} else {
msg += '\n.....No more kids this node';
}
if (g.nextSibling){
msg += '\n.....Some sibs this node';
} else {
msg += '\n......No sibs this node';
} } }
alert(msg);
}

function addElement(theThing) {
if( !document.createElement || !document.childNodes ) {
window.alert('Your browser is not DOM compliant');
} else {
var thisRow = theThing.parentNode.parentNode;
var newElement = thisRow.cloneNode(true);
reportKids(newElement,'After clone, before add');

// The following lines work perfectly in Firefox but not IE
// newElement.childNodes[0].childNodes[1].reset();
// newElement.childNodes[0].childNodes[1].className = 'formBlur';

thisRow.parentNode.insertBefore(newElement,thisRow );
reportKids(newElement,'After add to table');
}}
</script>
</head>
<body style="font-family: sans-serif; color: #555555">
<table cellpadding="3"><tr><td width="400">

<p>Put some text in the field, then click the "Clone" button.
Function addElement gets the row that the form is in
(theThing.parent.parent), clones it
and adds the clone to the table.</p>

<p>Firefox and IE clone everything, including
the content (value) of the text area. I
wanted to reset the text area value and change
the style of the form, but I can't navigate
to either of them in IE using the tr reference
(newElement) as a starting point.</p>

<p>addElement shows alert boxes with the tree
of children of the cloned table row before and
after adding to the table. The extra "no more
kids/siblings" tests just show there's nothing more
to navigate to. The Report Kids button shows the
same thing for the row in the current page. This
was to show the tree is exactly the same at each
of the stages for each particular browser, but
different across browsers.</p>

<p>Firefox has everything there, but IE doesn't. How can
I reset the value of the text field and change the style
of the cloned form if I can't get to them from the tr
reference?</p>

</td></tr>
<tr><td>
<form name="aForm">
<input type="text" name="aText">
<input
type="button" name="aButton"
value="Clone"
onclick="addElement(this.form);"
onfocus="this.blur();">
<input type="button" name="bButton"
value="Report Kids"
onclick="reportKids(
this.form.parentNode.parentNode,
'native HTML');"

</form>
</td></tr>
<tr><td>
<p>The alert box contains all the children and subchildren of
the cloned <tr>

<p>Another interesting thing is that JavaScript has an
insertBefore method, but not an insertAfter - why not?
It means I have to put the cloned row before the current
row, which is not logical for my application. appendChild
to the table is very inconsistent across browsers, so I
can't use that (result is navigation issues above x 10!).
</td></tr></table>

</body>
</html
-
Rob

Jul 23 '05 #1
4 3423
Dont know if this is the answer to your problem but:

replacing:

newElement.childNodes[0].childNodes[1].reset();
newElement.childNodes[0].childNodes[1].className = 'formBlur';

with:

newElement.childNodes[0].childNodes[0].reset();
newElement.childNodes[0].childNodes[0].className = 'formBlur';

makes it work fine in my IE6.

(alert(newElement.childNodes[0].childNodes[0].tagName) returns 'FORM')
Oeyvind
--
http://home.online.no/~oeyvtoft/ToftWeb/

"RobG" <Ro*********@mail.forum4designers.com> skrev i melding
news:Ro*********@mail.forum4designers.com...

I have a problem navigating a form in a table in IE using
the DOM. I can do what I want in Firefox, but not in IE.
The rest of my question and information is embedded
in the following code. Sorry, I don't have a web page to
publish it in.

I have tried to make it so it will copy and paste OK.

<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title> Clone Puzzle </title>

<script type="text/javascript">
function reportKids(thing,txt) {
var f = thing.childNodes;
var preTxt = '';
var msg = txt;
for (var i=0; i<f.length; ++i){
msg += '\nChild ' + i + ' is a ' + f[i];
var g = f[i].childNodes;
for (var j=0; j<g.length; ++j){
preTxt = '\nChild ' + i + ', subChild '
msg += preTxt +
j + ' is a ' + g[j] +
' of type ' + g[j].nodeType;
if (g.childNodes){
msg += '\n.....More kids this node';
} else {
msg += '\n.....No more kids this node';
}
if (g.nextSibling){
msg += '\n.....Some sibs this node';
} else {
msg += '\n......No sibs this node';
} } }
alert(msg);
}

function addElement(theThing) {
if( !document.createElement || !document.childNodes ) {
window.alert('Your browser is not DOM compliant');
} else {
var thisRow = theThing.parentNode.parentNode;
var newElement = thisRow.cloneNode(true);
reportKids(newElement,'After clone, before add');

// The following lines work perfectly in Firefox but not IE
// newElement.childNodes[0].childNodes[1].reset();
// newElement.childNodes[0].childNodes[1].className = 'formBlur';

thisRow.parentNode.insertBefore(newElement,thisRow );
reportKids(newElement,'After add to table');
}}
</script>
</head>
<body style="font-family: sans-serif; color: #555555">
<table cellpadding="3"><tr><td width="400">

<p>Put some text in the field, then click the "Clone" button.
Function addElement gets the row that the form is in
(theThing.parent.parent), clones it
and adds the clone to the table.</p>

<p>Firefox and IE clone everything, including
the content (value) of the text area. I
wanted to reset the text area value and change
the style of the form, but I can't navigate
to either of them in IE using the tr reference
(newElement) as a starting point.</p>

<p>addElement shows alert boxes with the tree
of children of the cloned table row before and
after adding to the table. The extra "no more
kids/siblings" tests just show there's nothing more
to navigate to. The Report Kids button shows the
same thing for the row in the current page. This
was to show the tree is exactly the same at each
of the stages for each particular browser, but
different across browsers.</p>

<p>Firefox has everything there, but IE doesn't. How can
I reset the value of the text field and change the style
of the cloned form if I can't get to them from the tr
reference?</p>

</td></tr>
<tr><td>
<form name="aForm">
<input type="text" name="aText">
<input
type="button" name="aButton"
value="Clone"
onclick="addElement(this.form);"
onfocus="this.blur();">
<input type="button" name="bButton"
value="Report Kids"
onclick="reportKids(
this.form.parentNode.parentNode,
'native HTML');"

</form>
</td></tr>
<tr><td>
<p>The alert box contains all the children and subchildren of
the cloned <tr>

<p>Another interesting thing is that JavaScript has an
insertBefore method, but not an insertAfter - why not?
It means I have to put the cloned row before the current
row, which is not logical for my application. appendChild
to the table is very inconsistent across browsers, so I
can't use that (result is navigation issues above x 10!).
</td></tr></table>

</body>
</html>

--
RobG

Jul 23 '05 #2
On Tue, 7 Sep 2004 00:43:56 -0500, RobG
<Ro*********@mail.forum4designers.com> wrote:
I have a problem navigating a form in a table in IE using
the DOM. I can do what I want in Firefox, but not in IE.
The rest of my question and information is embedded
in the following code. Sorry, I don't have a web page to
publish it in.
The problem you're seeing is a simple one, but very annoying nevertheless.

As you should know, elements aren't the only things present in the
document tree. The text contained within an element, even if it's just
whitespace (!), is also included. The problem here is that different
browsers use different rules when building the tree. Whereas some browsers
(like Firefox) include text nodes between elements, others (like IE) do
not. When you reference childNodes[0].childNodes[1], the resulting Node is
a FORM element in Firefox, but nothing in IE. If you referenced
childNodes[0].childNodes[0], the Node would be a FORM in IE, but a text
node in Firefox.

Your only solution is to walk the tree from a known location, checking the
node type. When you have a text node, skip it. When you have an element
node, use it!

[snip]
<p>Another interesting thing is that JavaScript has an
insertBefore method, but not an insertAfter - why not?
Because you'd only need one of those. The other is simply a matter of
using nextSibling or previousSibling. If there is no sibling, you'd get
null which the method will interpret as an append or prepend[1] operation.
It means I have to put the cloned row before the current
row, which is not logical for my application. appendChild
to the table is very inconsistent across browsers, so I
can't use that (result is navigation issues above x 10!).


Do you really mean appendChild, or are you referring to insertRow? I would
have thought the latter to be a much better choice. :)

[snip]

Good luck,
Mike
[1] Should insertAfter exist.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
On Tue, 7 Sep 2004 10:06:05 +0200, oeyvind toft <oe******@online.no> wrote:
Dont know if this is the answer to your problem but:

replacing:

newElement.childNodes[0].childNodes[1].reset();
newElement.childNodes[0].childNodes[1].className = 'formBlur';

with:

newElement.childNodes[0].childNodes[0].reset();
newElement.childNodes[0].childNodes[0].className = 'formBlur';

makes it work fine in my IE6.


Yes, but as I said in my post, it'll stop working in Firefox.

Mike
Would you please stop top-posting.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
Sure .o)

--
http://home.online.no/~oeyvtoft/ToftWeb/

"Michael Winter" <M.******@blueyonder.co.invalid> skrev i melding
news:opsdx6woiyx13kvk@atlantis...
On Tue, 7 Sep 2004 10:06:05 +0200, oeyvind toft <oe******@online.no> wrote:
Dont know if this is the answer to your problem but:

replacing:

newElement.childNodes[0].childNodes[1].reset();
newElement.childNodes[0].childNodes[1].className = 'formBlur';

with:

newElement.childNodes[0].childNodes[0].reset();
newElement.childNodes[0].childNodes[0].className = 'formBlur';

makes it work fine in my IE6.


Yes, but as I said in my post, it'll stop working in Firefox.

Mike
Would you please stop top-posting.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Jul 23 '05 #5

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

Similar topics

4
by: Dave Patton | last post by:
Using my About page as an example: http://members.shaw.ca/davepatton/about.html What is the best/proper way to markup a page such as this that has "the main body" and "a navigation menu"? It...
0
by: Veli-Pekka Tätilä | last post by:
Hi, My first post here. I've found some serious accessibility flaws in the Python 2.4 docs and wish they could be rectified over time. I'm very new to Python and initially contacted docs at python...
1
by: Robert Neville | last post by:
I am having some trouble with some old code revolving around custom form navigation buttons. My main form has a sub-form with these custom navigation buttons. In other words, the code should be...
4
by: Sandy.Pittendrigh | last post by:
I don't want to get into a frames discussion here. We all know they have numerous drawbacks, especially with search engine visibility. (Google, ironically, uses framesets for displaying individual...
28
by: laredotornado | last post by:
Hi, Surprisingly, I can't get the drop down menus to work on PC IE 6. If you roll over "PRODUCTS", normally a drop down menu appears (on Safari and Firefox), but on PC IE, nada. ...
3
by: Paul | last post by:
I want the <div id="navigation"column to be the same color all the way to the bottom. The "background-image: url(bg_menu_tile.gif);" was a try to force it with a long 1-pixel graphic - didn't...
10
by: EA | last post by:
I am sure I must be missing something about building navigation bars with CSS. Yes it is a very clever and efficient way to format navigation structures on simple one navigation level webs, i.e....
1
by: quartzy | last post by:
I have a strict doc type: However, I am still unsure about css. Problems I have now are to do with floating both navigation lists. I have used tables and divs, as layouts are just too difficult for...
0
by: emalcolm_FLA | last post by:
Hello and TIA for your consideration. I have created several db's for a non-profit and they want custom navigation buttons to display "You are on the first record, last record, etc". With this...
0
by: tom59593 | last post by:
Hi there. I have been attempting (for a few days on end, sadly) to get a navigation section of my new site to work. Granted, this is the first time I've ever written CSS...although I had PLENTY of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...

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.