473,568 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need HELP: Firefox/nodeValue oddity

Hello,

When I try to insert this line of code into my script, Firefox refuses to
render. Could someone explain to me why that is?

if (x[i].firstChild.fir stChild.nodeVal ue==productID) {
some code
}

full code listed below:

HTML BODY
=============== =============== =
<div id="writeroot"> </div>
<script type="text/javascript">
importXML("pric es.xml", priceTable, "kenko", "L37 Super PRO");
</script>
JAVASCRIPT
=============== =============== =
function importXML(xmlFi le, xmlDisplay, para1, para2) {
if (window.ActiveX Object) {
xmlDoc = new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.onreadys tatechange = function () {
if (xmlDoc.readySt ate == 4) xmlDisplay(para 1, para2);
}
} else if (document.imple mentation &&
document.implem entation.create Document) {
xmlDoc = document.implem entation.create Document("", "", null);
xmlDoc.onload = function() {
xmlDisplay(para 1, para2);
}
} else {
alert('Sorry, your browser doesn't support XML scripting');
return;
}
xmlDoc.async = "false";
xmlDoc.load(xml File);
}

function priceTable(prod uctCat, productID) {
var pCat = xmlDoc.getEleme ntsByTagName(pr oductCat);
var x = pCat[0].getElementsByT agName("item");

var newTable = document.create Element("table" );
newTable.setAtt ribute("border" ,1);
var tableBody = document.create Element("tbody" );
newTable.append Child(tableBody );
var row = document.create Element("tr");
var emptyCell = document.create Element("th");
row.appendChild (emptyCell);
for (j=3; j<x[0].childNodes.len gth; j++) {
if (x[0].childNodes[j].nodeType != 1) continue;
var container = document.create Element("th");
var theData = document.create TextNode(x[0].childNodes
[j].nodeName.subst ring(1));
container.appen dChild(theData) ;
row.appendChild (container);
}

tableBody.appen dChild(row);

for (i=0; i<x.length; i++) {
var row = document.create Element("tr");
// if (x[i].firstChild.fir stChild.nodeVal ue==productID) {
if (window.ActiveX Object) {
row.style.setAt tribute("cssTex t", "background-color:
#cfc;");
} else if (document.imple mentation &&
document.implem entation.create Document) {
row.setAttribut e("style", "background-color:
#cfc;");
}
// }
var nameCell = document.create Element("th");
var productName = document.create TextNode(x[i].childNodes
[1].firstChild.nod eValue);
nameCell.append Child(productNa me);
row.appendChild (nameCell);
for (j=3; j<x[i].childNodes.len gth; j++) {
if (x[i].childNodes[j].nodeType != 1) continue;
var priceCell = document.create Element("td");
var priceData = document.create TextNode(x[i].childNodes
[j].firstChild==nu ll ? "" : x[i].childNodes[j].firstChild.nod eValue);
priceCell.appen dChild(priceDat a);
row.appendChild (priceCell);
}
tableBody.appen dChild(row);
}
document.getEle mentById("write root").appendCh ild(newTable);
}
XML
=============== =====
<products>
<lens>
<uv>
<item>
<en>kenko</en>
<gb>L37</gb>
<description>
</description>
<d49mm>132</d49mm>
<d52mm>143</d52mm>
<d55mm>160</d55mm>
<d58mm>170</d58mm>
<d62mm>210</d62mm>
<d67mm>245</d67mm>
<d72mm>285</d72mm>
<d77mm>320</d77mm>
<d82mm>425</d82mm>
<d86mm>715</d86mm>
</item>
</uv>
</lens>
</products>
Jul 23 '05 #1
1 4787


Stone Chen wrote:
When I try to insert this line of code into my script, Firefox refuses to
render. Could someone explain to me why that is?

if (x[i].firstChild.fir stChild.nodeVal ue==productID) {
some code
}


It is not clear what you are trying to achieve but using childNodes
respectively firstChild and lastChild and expecting a certain kind of
node when you deal with the DOM is prone to errors, DOM implementation
have different ways of dealing with whitespace text nodes in the DOM,
some (Mozilla HTML and XML DOM) include them always, some (IE HTML DOM)
ignore the always, some (MSXML XML DOM) have settings on whether to
ignore them. Thus if you have
<gods>
<god>Kibo</god>
<god>Xibo</god>
</gods>
then with some implementations
xmlDocument.doc umentElement.fi rstChild
is a text node with white space, with others it is the <god>Kibo</god>
element node.
Therefore don't navigate firstChild/lastChild/childNodes without
checking the nodeType or better avoid accessing child node if element
nodes are all what you are looking for then use getElementsByTa gName or
make sure you walk childNodes node by node until you find the right
nodeType (1 for element nodes, 3 for text nodes).

If you have further problems then try to make a reduced test case and
post a URL but tell us exactly what the Firefox JavaScript console says.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

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

Similar topics

3
1910
by: diablo | last post by:
hi i have a table (leftmenu), the cells of this table has a <A> link in them. <table class="menu_table" width="100%" cellspacing="0" cellpadding="0" id="leftmenu"> <tr> <td><a class="menu_link" href="/hb/home/">Home</a></td> </tr> </table>
4
12202
by: leodippolito | last post by:
Hello sirs, I am trying to send a POST request to a webservice on the click of a button. This will return me an XML document with a list of combo box items. The problem: in FIREFOX, when the get the XmlDocument from the XmlHttpRequest object, I can't access its contents. I keep getting empty strings and "null".
6
4021
by: laramie.hartmann | last post by:
I have a script (see below) that accesses a XML file and displays the contents through a series of document.write calls. This all works fine in IE, but not at all in Firefox. I get no errors in the javascript console, but when I try to load the elements by tag name and look at the length it is always 0 as if no elements have been added. Any...
4
1418
by: windandwaves | last post by:
Hi Folk Can you please have a look at http://www.friars.co.nz/map.php and let me know if the map is working on IE6 (just do a simple search). Unfortunately, I do not have IE6 anymore and so I can not test it. I think there maybe some trouble with retrieving the AJAX xml. Below is the code for this: var i = new Array();
2
2089
by: hzgt9b | last post by:
I've written a simple javascript page that parses an XML file... (Actually I just modified the "Parsing an XML File" sample from http://www.w3schools.com/dom/dom_parser.asp) The page works great standalone... but when I try to make this work under frames I get "Error: Object required" when the following line executes:...
3
2573
by: jpk872 | last post by:
I've got an image, when I mouse over it a popup window shows and the person's hobbies are displayed using a CSS popup window. It works in IE, but not Firefox. Any idea why? (lines 23-31) <img name=showHobbies src="" style="position:absolute;left:550;top:25;width:100;height:50" onmouseover="show(fullfile)" onmouseout="hide()"> ...
5
2229
by: jpk872 | last post by:
I've got an image, when I mouse over it a popup window shows and the person's hobbies are displayed using a CSS popup window. It works in IE, but not Firefox. Any idea why? (lines 23-31) <img name=showHobbies src="" style="position:absolute;left:550;top:25;width:100;height:50" onmouseover="show(fullfile)" onmouseout="hide()"> ...
13
2606
by: Gretsch | last post by:
Re XML, Javascript, IE, Firefox Hi, I have a very simple & small XML file (only 7 variables). The code works for IE, but not for Firefox. I've search around and found lots of alternatives, but all different and mostly way above my competance level to understand (ieg Ajax;-(). Could someone give me some guidance please. - thanks ...
8
1885
by: chanshaw | last post by:
Alright this runs just fine in IE but in firefox I get nothing function startup() { if (window.ActiveXObject) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } else if (document.implementation.createDocument)
0
7693
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...
1
7660
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...
0
7962
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...
0
6275
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...
1
5498
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...
0
5217
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...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
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.