Cannot run this code

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>
---------------------------------------------------------------------
file:prices.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>
----------------------------------------------------------
file:prices.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>
 
M

Martin Honnen

tepaul said:
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

Lots of code telling without telling us which line and which browser
yields that error.
Does the error occur here
searchPrice(children.item(i),ouput,rate);
^^^^^

That seems to be a typo, ouput instead of output.
 
T

tepaul

Sorry not clearly describe the problem
-When I try to run the code, and click the convert the alert popup say
that
in the function convert
output.value="" is undefine

thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,002
Messages
2,570,261
Members
46,859
Latest member
VallieMcKe

Latest Threads

Top