Tom de Neef wrote:
"James Kimble" <jk*****@one.netschreef in bericht
>Yeah I'm sure this is a stupid question.
There are no stupid questions. There are only stupid answers.
Such as yours?
>[...]
This just displays my graph by itself. No other table items appear.
Some suggestions:
<head>
<script type="text/JavaScript" src="bargraph.js"></script>
The <script ...tag that was in the original code is missing here.
function createBarGraph() {
graph = new BarGraph("HorizBar");
`graph' should be declared a variable, globally if used outside of
createBarGraph(), locally if not.
// global declaration
var graph;
or
// local declaration and initialization;
var graph = new BarGraph(...);
graph.values = "1000";
return graph.create()
The trailing `;' is missing; it is optional here, but recommended.
}
</script>
</head>
Chech the <scripttag for its attributes
You should be more precise and more verbose about your suggestions. The
point here is that the `type' attribute is required for the `script'
_element_, and it was not provided yet which renders the markup invalid.
document.write removed. Its intention is to replace the current page.
There is no intention of a method in itself; *people* have intentions. What
document.write() does, however, depends on where and when it is used, as
already explained before. (Please try to read all accessible postings of a
thread before you are posting late to it.)
That is not what you want.
True.
The function now returns the (html) string produced by
graph.create(). At least I guess that's what graph.create() will return.
But this is the major problem with this question. One can only guess
because the OP is not verbose enough.
[...]
<td id=graphcell</td>
All attribute values should be quoted.
[...]
That cell will be empty when loaded. In the onLoad handler you now call
script code that will fill the cell with your graph.
I.e. you could do with another function within your script:
function placeGraph(id)
{ var cell = document.getElementById(id)
cell.innerHTML = createBarGraph()
}
and with
<body onLoad="placeGraph('graphcell')">
it should work.
However, without further feature tests this is just a big overhead.
Of course, you can combine these things and use
<body
onLoad="document.getElementById(graphcell).innerHT ML=createBarGraph()">
Needs to be
onLoad="document.getElementById('graphcell').inner HTML=createBarGraph()">
for a remote chance of working. However, it would be better if
createBarGraph() and consequently graph.create() returned a reference to a
DOM Node object so that it can be inserted as child node of the element node
referred to by the equivalent of document.getElementById('graphcell'), and
maybe replace existing child nodes. (Maybe this is already the case so that
it could not be done by the OP without learning about DOM mutator methods.)
and do without the extra function if you really want to push your code on
the track of unmaintainability.
With your approach it is on that track already.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>