T
tepaul
I am new to the DOM, but i try to figure out this simple tutorial on
the book, and make it extractly the same as it is written.
but when I run the program it okay, but when I click on the covert
button it says that it is output is undefined
Main File
---------------------------------------------------------------------
<html>
<head><title>
Currency Conversion
</title></head>
<FRAMESET COLS="40%,60%">
<FRAME SRC="conversion.html" NAME="conversion">
<FRAME SRC="prices.xml" NAME="xml">
</FRAMESET>
</html>
---------------------------------------------------------------------
filerices.xml
==============
<?xml version="1.0" ?>
<?xml-stylesheet href="prices.css" type="text/css"?>
<products>
<product>
<name> xML editor</name>
<price> 45.33</price>
</product>
<product>
<name>ebook</name>
<price> 4.33</price>
</product>
<product>
<name> java</name>
<price> 145.33</price>
</product>
<product>
<name> cocola</name>
<price> 34.3</price>
</product>
</products>
----------------------------------------------------------
filerices.css
==============
product
{
display: block;
font-family: Palatino,Garamond, "Times New Roman", serif;
}
name
{
font-weight: bold;
}
---------------------------------------------------------------------
file:Conversion.html
===================
<HTML><HEAD>
<TITLE>Conversion</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function convert(form,xmldocument)
{
var output= form.output;
rate = form.rate.value;
output.value="";
var toplevel= xmldocument.documentElement;
searchPrice(toplevel,output,rate)
}
function searchPrice(node,output,rate)
{
if(node.nodeType==1)
{
if(node.nodeName == "price")
output.value +=(getText(node) * rate) + "\r";
var children, i ;
children = node.childNodes;
for(i=0; i < children.length; i++)
searchPrice(children.item(i),ouput,rate);
}
}
function getText(node)
{
if(node.nodeType == 1)
{
var text="",
children=node.chilNodes, i;
for(i=0; i<children.length; i++)
if(children.item(i).nodeType== 3)
text+=children.item(i).data;
return text;
}
else
return "";
}
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<FORM ID="controls">
Rate: <INPUT TYPE="TEXT" NAME="rate" VALUE="0.9333" SIZE="4"><BR>
<INPUT TYPE="BUTTON"
ONCLICK="convert(controls,parent.xml.document)" VALUE="Convert">
<INPUT TYPE="BUTTON" VALUE="Clear" ONCLICK="output.value=''"><BR>
<TExTAREA NAME="output" ROWS="10" COLS="30"></TExTAREA>
</FORM>
</CENTER>
</BODY>
</HTML>
the book, and make it extractly the same as it is written.
but when I run the program it okay, but when I click on the covert
button it says that it is output is undefined
Main File
---------------------------------------------------------------------
<html>
<head><title>
Currency Conversion
</title></head>
<FRAMESET COLS="40%,60%">
<FRAME SRC="conversion.html" NAME="conversion">
<FRAME SRC="prices.xml" NAME="xml">
</FRAMESET>
</html>
---------------------------------------------------------------------
filerices.xml
==============
<?xml version="1.0" ?>
<?xml-stylesheet href="prices.css" type="text/css"?>
<products>
<product>
<name> xML editor</name>
<price> 45.33</price>
</product>
<product>
<name>ebook</name>
<price> 4.33</price>
</product>
<product>
<name> java</name>
<price> 145.33</price>
</product>
<product>
<name> cocola</name>
<price> 34.3</price>
</product>
</products>
----------------------------------------------------------
filerices.css
==============
product
{
display: block;
font-family: Palatino,Garamond, "Times New Roman", serif;
}
name
{
font-weight: bold;
}
---------------------------------------------------------------------
file:Conversion.html
===================
<HTML><HEAD>
<TITLE>Conversion</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function convert(form,xmldocument)
{
var output= form.output;
rate = form.rate.value;
output.value="";
var toplevel= xmldocument.documentElement;
searchPrice(toplevel,output,rate)
}
function searchPrice(node,output,rate)
{
if(node.nodeType==1)
{
if(node.nodeName == "price")
output.value +=(getText(node) * rate) + "\r";
var children, i ;
children = node.childNodes;
for(i=0; i < children.length; i++)
searchPrice(children.item(i),ouput,rate);
}
}
function getText(node)
{
if(node.nodeType == 1)
{
var text="",
children=node.chilNodes, i;
for(i=0; i<children.length; i++)
if(children.item(i).nodeType== 3)
text+=children.item(i).data;
return text;
}
else
return "";
}
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<FORM ID="controls">
Rate: <INPUT TYPE="TEXT" NAME="rate" VALUE="0.9333" SIZE="4"><BR>
<INPUT TYPE="BUTTON"
ONCLICK="convert(controls,parent.xml.document)" VALUE="Convert">
<INPUT TYPE="BUTTON" VALUE="Clear" ONCLICK="output.value=''"><BR>
<TExTAREA NAME="output" ROWS="10" COLS="30"></TExTAREA>
</FORM>
</CENTER>
</BODY>
</HTML>