Re: Javascript in an HTML table
- From: Thomas 'PointedEars' Lahn <PointedEars@xxxxxx>
- Date: Sun, 08 Jun 2008 11:46:16 +0200
[previous posting superseded in the face of new evidence]
Tom de Neef wrote:
"James Kimble" <jkimble@xxxxxxx> schreef 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 <script> tag 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.
[...]
<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).innerHTML=createBarGraph()">
Needs to be
onLoad="document.getElementById('graphcell').innerHTML=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. 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 code 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, <f806at$ail$1$8300dec7@xxxxxxxxxxxxxxxx>
.
- References:
- Javascript in an HTML table
- From: James Kimble
- Re: Javascript in an HTML table
- From: Tom de Neef
- Javascript in an HTML table
- Prev by Date: Re: Javascript in an HTML table
- Next by Date: Re: Javascript in an HTML table
- Previous by thread: Re: Javascript in an HTML table
- Next by thread: Re: Javascript in an HTML table
- Index(es):
Relevant Pages
|