Javascript in an HTML table

Discussion in 'Javascript' started by James Kimble, Jun 5, 2008.

  1. James Kimble

    James Kimble Guest

    Yeah I'm sure this is a stupid question.

    I've got a javascript source file with functions (creates a bar graph)
    I want to call from inside an html table cell so that the graph
    appears in the cell. I've tried a bunch of different things but I'm
    not getting it. I'm a newbee to both html and javascript so be kind.

    Any example would be appreciated.


    My current attempt looks like:

    <head>
    <script language="JavaScript" src="bargraph.js"></script>
    <script language="JavaScript">
    function createBarGraph() {
    graph = new BarGraph("HorizBar");
    graph.values = "1000";
    document.write(graph.create());
    }
    </script>
    </head>
    <body onLoad="createBarGraph()">
    <table width="100%" border="0">
    <tr>
    <td>HPX40</td>
    <td>CUSTOMER DEFINED TEXT </td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>Plate Status:</td>
    <td><form name="f1" action="javascript:createBarGraph()"
    method="post"></td>
    <td>40.5KW</td>
    </tr>
    </table>
    </body>

    This just displays my graph by itself. No other table items appear.
     
    James Kimble, Jun 5, 2008
    #1
    1. Advertising

  2. On Thu, 05 Jun 2008 10:12:32 -0700, James Kimble wrote:

    > Yeah I'm sure this is a stupid question.
    >
    > I've got a javascript source file with functions (creates a bar graph) I
    > want to call from inside an html table cell so that the graph appears in
    > the cell. I've tried a bunch of different things but I'm not getting it.
    > I'm a newbee to both html and javascript so be kind.
    >
    > Any example would be appreciated.
    >
    >
    > My current attempt looks like:
    >
    > <head>
    > <script language="JavaScript" src="bargraph.js"></script>
    > <script language="JavaScript">
    > function createBarGraph() {
    > graph = new BarGraph("HorizBar");
    > graph.values = "1000";
    > document.write(graph.create());
    > }
    > </script>
    > </head>
    > <body onLoad="createBarGraph()">
    > <table width="100%" border="0">
    > <tr>
    > <td>HPX40</td>
    > <td>CUSTOMER DEFINED TEXT </td>
    > <td>&nbsp;</td>
    > </tr>
    > <tr>
    > <td>Plate Status:</td>
    > <td><form name="f1" action="javascript:createBarGraph()"
    > method="post"></td>
    > <td>40.5KW</td>
    > </tr>
    > </table>
    > </body>
    >
    > This just displays my graph by itself. No other table items appear.


    This is correct, though unexpected, behavior.

    If you call "document.write" WHILE THE PAGE IS LOADING, then it will kind
    of 'slip' stuff into your web page.

    However, you are calling it AFTER the page has loaded, which will REPLACE
    the contents of your page with the new information. Many folks consider
    document.write problematic at best recommend avoiding it.

    In addition, the coding style that you are using is very obsolete. You
    might want to consider reading this:

    <URL: http://www.mopedepot.com/jjs/HowToRecognizeBadJavascriptCode.html >
     
    Jeremy J Starcher, Jun 5, 2008
    #2
    1. Advertising

  3. James Kimble

    James Kimble Guest

    Ok, but what would be the correct way to do this (ie. show the table
    with the graph in it)?


    On Jun 5, 2:00 pm, Jeremy J Starcher <> wrote:
    > On Thu, 05 Jun 2008 10:12:32 -0700, James Kimble wrote:
    > > Yeah I'm sure this is a stupid question.

    >
    > > I've got a javascript source file with functions (creates a bar graph) I
    > > want to call from inside an html table cell so that the graph appears in
    > > the cell. I've tried a bunch of different things but I'm not getting it.
    > > I'm a newbee to both html and javascript so be kind.

    >
    > > Any example would be appreciated.

    >
    > > My current attempt looks like:

    >
    > > <head>
    > > <script language="JavaScript" src="bargraph.js"></script>
    > > <script language="JavaScript">
    > > function createBarGraph() {
    > > graph = new BarGraph("HorizBar");
    > > graph.values = "1000";
    > > document.write(graph.create());
    > > }
    > > </script>
    > > </head>
    > > <body onLoad="createBarGraph()">
    > > <table width="100%" border="0">
    > > <tr>
    > > <td>HPX40</td>
    > > <td>CUSTOMER DEFINED TEXT </td>
    > > <td> </td>
    > > </tr>
    > > <tr>
    > > <td>Plate Status:</td>
    > > <td><form name="f1" action="javascript:createBarGraph()"
    > > method="post"></td>
    > > <td>40.5KW</td>
    > > </tr>
    > > </table>
    > > </body>

    >
    > > This just displays my graph by itself. No other table items appear.

    >
    > This is correct, though unexpected, behavior.
    >
    > If you call "document.write" WHILE THE PAGE IS LOADING, then it will kind
    > of 'slip' stuff into your web page.
    >
    > However, you are calling it AFTER the page has loaded, which will REPLACE
    > the contents of your page with the new information. Many folks consider
    > document.write problematic at best recommend avoiding it.
    >
    > In addition, the coding style that you are using is very obsolete. You
    > might want to consider reading this:
    >
    > <URL:http://www.mopedepot.com/jjs/HowToRecognizeBadJavascriptCode.html>
     
    James Kimble, Jun 6, 2008
    #3
  4. On Fri, 06 Jun 2008 09:58:15 -0700, James Kimble wrote:

    [Posting order restored. Please don't top-post on USENET]

    >
    > On Jun 5, 2:00 pm, Jeremy J Starcher <> wrote:
    >> On Thu, 05 Jun 2008 10:12:32 -0700, James Kimble wrote:
    >> > Yeah I'm sure this is a stupid question.

    >>
    >> > I've got a javascript source file with functions (creates a bar
    >> > graph) I want to call from inside an html table cell so that the
    >> > graph appears in the cell. I've tried a bunch of different things but
    >> > I'm not getting it. I'm a newbee to both html and javascript so be
    >> > kind.

    >>
    >> > Any example would be appreciated.

    >>
    >> > My current attempt looks like:


    [Code snipped]

    >> This is correct, though unexpected, behavior.
    >>
    >> If you call "document.write" WHILE THE PAGE IS LOADING, then it will
    >> kind of 'slip' stuff into your web page.
    >>
    >> However, you are calling it AFTER the page has loaded, which will
    >> REPLACE the contents of your page with the new information. Many folks
    >> consider document.write problematic at best recommend avoiding it.


    > Ok, but what would be the correct way to do this (ie. show the table
    > with the graph in it)?


    The correct way would be to use the DOM methods to create elements and
    insert them into the document, or to create the graph server-side.

    <URL: http://www.quirksmode.org/dom/intro.html >

    you might also get away with using innerHTML, but I have been getting
    away from that.
     
    Jeremy J Starcher, Jun 6, 2008
    #4
  5. James Kimble

    James Kimble Guest

    On Jun 6, 6:20 pm, Jeremy J Starcher <> wrote:
    > On Fri, 06 Jun 2008 09:58:15 -0700, James Kimble wrote:
    >
    > [Posting order restored. Please don't top-post on USENET]
    >
    >
    >
    > > On Jun 5, 2:00 pm, Jeremy J Starcher <> wrote:
    > >> On Thu, 05 Jun 2008 10:12:32 -0700, James Kimble wrote:
    > >> > Yeah I'm sure this is a stupid question.

    >
    > >> > I've got a javascript source file with functions (creates a bar
    > >> > graph) I want to call from inside an html table cell so that the
    > >> > graph appears in the cell. I've tried a bunch of different things but
    > >> > I'm not getting it. I'm a newbee to both html and javascript so be
    > >> > kind.

    >
    > >> > Any example would be appreciated.

    >
    > >> > My current attempt looks like:

    >
    > [Code snipped]
    >
    > >> This is correct, though unexpected, behavior.

    >
    > >> If you call "document.write" WHILE THE PAGE IS LOADING, then it will
    > >> kind of 'slip' stuff into your web page.

    >
    > >> However, you are calling it AFTER the page has loaded, which will
    > >> REPLACE the contents of your page with the new information. Many folks
    > >> consider document.write problematic at best recommend avoiding it.

    > > Ok, but what would be the correct way to do this (ie. show the table
    > > with the graph in it)?

    >
    > The correct way would be to use the DOM methods to create elements and
    > insert them into the document, or to create the graph server-side.
    >
    > <URL:http://www.quirksmode.org/dom/intro.html>
    >
    > you might also get away with using innerHTML, but I have been getting
    > away from that.


    Not big on examples are ya.....

    I'm really just trying to throw something together. Getting it done in
    the purest form of correctness is not required or even particularly
    desirable because this is to be a rough demo. Not a finished product.
    This seems like it should be a "really" simple thing to do and yes,
    I'm being lazy about learning the languages because I don't use them
    and never intend to use them much (I work in C and Java mostly in the
    embedded environment).

    So I guess I'll go to the book store and do a little reading. I do
    appreciate your guidance but I was really just looking for a simple
    "do this" type response to the snippet of code I posted. I realize
    it's better to teach how to fish rather than just give a fish but, in
    this case, I never wanted to be a fisherman 'cause I'm eating pretty
    well on the king crab I catch in my part of the ocean.

    Thank you anyway.....
     
    James Kimble, Jun 8, 2008
    #5
  6. James Kimble wrote:
    > On Jun 6, 6:20 pm, Jeremy J Starcher <> wrote:
    >> On Fri, 06 Jun 2008 09:58:15 -0700, James Kimble wrote:
    >>> Ok, but what would be the correct way to do this (ie. show the table
    >>> with the graph in it)?

    >> The correct way would be to use the DOM methods to create elements and
    >> insert them into the document, or to create the graph server-side.
    >>
    >> <URL:http://www.quirksmode.org/dom/intro.html>
    >>
    >> you might also get away with using innerHTML, but I have been getting
    >> away from that.

    >
    > Not big on examples are ya.....


    Usenet is not a right.

    > [...]
    > This seems like it should be a "really" simple thing to do and yes,


    How could you even know?

    > I'm being lazy about learning the languages because I don't use them
    > and never intend to use them much (I work in C and Java mostly in the
    > embedded environment).


    But with this attitude you are not likely to get a straight answer out of
    anyone who can be taken seriously around here because it is like asking them
    to do your homework in their leisure time for free. You are looking for
    someone who you can pay for the answer instead.

    See also:

    http://jibbering.com/faq/
    http://www.catb.org/~esr/faqs/smart-questions.html


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
     
    Thomas 'PointedEars' Lahn, Jun 8, 2008
    #6
  7. James Kimble

    Tom de Neef Guest

    "James Kimble" <> schreef in bericht
    news:...
    >
    >
    > Yeah I'm sure this is a stupid question.

    There are no stupid questions. There are only stupid answers.
    >
    > I've got a javascript source file with functions (creates a bar graph)
    > I want to call from inside an html table cell so that the graph
    > appears in the cell. I've tried a bunch of different things but I'm
    > not getting it. I'm a newbee to both html and javascript so be kind.
    >
    > Any example would be appreciated.
    >
    >
    > My current attempt looks like:
    >
    > <head>
    > <script language="JavaScript" src="bargraph.js"></script>
    > <script language="JavaScript">
    > function createBarGraph() {
    > graph = new BarGraph("HorizBar");
    > graph.values = "1000";
    > document.write(graph.create());
    > }
    > </script>
    > </head>
    > <body onLoad="createBarGraph()">
    > <table width="100%" border="0">
    > <tr>
    > <td>HPX40</td>
    > <td>CUSTOMER DEFINED TEXT </td>
    > <td>&nbsp;</td>
    > </tr>
    > <tr>
    > <td>Plate Status:</td>
    > <td><form name="f1" action="javascript:createBarGraph()"
    > method="post"></td>
    > <td>40.5KW</td>
    > </tr>
    > </table>
    > </body>
    >
    > This just displays my graph by itself. No other table items appear.
    >


    Some suggestions:
    <head>
    <script type="text/JavaScript" src="bargraph.js"></script>
    function createBarGraph() {
    graph = new BarGraph("HorizBar");
    graph.values = "1000";
    return graph.create()
    }
    </script>
    </head>

    Chech the <script> tag for its attributes
    document.write removed. Its intention is to replace the current page. That
    is not what you want. The function now returns the (html) string produced by
    graph.create(). At least I guess that's what graph.create() will return.
    But you need more: you want to place this text inside a table cell.
    Conceptually, the html - as a string - would read like this:
    '<td>'+createBarGraph()+'</td>'. You can make this happen if you can
    identify the table cell. So, give it an ID, like
    <table>
    <tr>
    <td> Plate Status:</td>
    <td id=graphcell> </td>
    <td>40.5KW</td>
    </tr>
    </table>
    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.

    Of course, you can combine these things and use
    <body
    onLoad="document.getElementById(graphcell).innerHTML=createBarGraph()">
    and do without the extra function if you really want to push your code on
    the track of unmaintainability.
    Tom
     
    Tom de Neef, Jun 8, 2008
    #7
  8. Tom de Neef wrote:
    > "James Kimble" <> 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.

    > 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).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. (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, <f806at$ail$1$>
     
    Thomas 'PointedEars' Lahn, Jun 8, 2008
    #8
  9. [previous posting superseded in the face of new evidence]

    Tom de Neef wrote:
    > "James Kimble" <> 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$>
     
    Thomas 'PointedEars' Lahn, Jun 8, 2008
    #9
  10. James Kimble <> writes:

    > I've got a javascript source file with functions (creates a bar graph)
    > I want to call from inside an html table cell so that the graph
    > appears in the cell.

    ....
    > <head>
    > <script language="JavaScript" src="bargraph.js"></script>


    Replace language="JavaScript" with type="text/javascript" to get
    valid HTML (the type attribute is required, the language attribute
    is irrelevant and deprecated).

    > <script language="JavaScript">
    > function createBarGraph() {
    > graph = new BarGraph("HorizBar");
    > graph.values = "1000";
    > document.write(graph.create());
    > }
    > </script>
    > </head>
    > <body onLoad="createBarGraph()">


    As others have said, this does document.write when the page has finished
    loaded, and the document has been closed. Which means that it replaces
    the curren document instead of appending to it.
    So don't call it here.

    > <table width="100%" border="0">
    > <tr>
    > <td>HPX40</td>
    > <td>CUSTOMER DEFINED TEXT </td>
    > <td>&nbsp;</td>
    > </tr>
    > <tr>
    > <td>Plate Status:</td>
    > <td><form name="f1" action="javascript:createBarGraph()"
    > method="post"></td>


    If you just want to put the bar graph here when the page is loading,
    you should just call your function:

    <td><script type="text/javascript">
    createBarGraph();
    </script>

    That will call document.write to insert HTML into the page just after
    the script element.

    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Jun 8, 2008
    #10
  11. On Sat, 07 Jun 2008 23:06:17 -0700, James Kimble wrote:

    > On Jun 6, 6:20 pm, Jeremy J Starcher <> wrote:
    >> On Fri, 06 Jun 2008 09:58:15 -0700, James Kimble wrote:
    >>
    >> [Posting order restored. Please don't top-post on USENET]
    >>
    >>
    >>
    >> > On Jun 5, 2:00 pm, Jeremy J Starcher <> wrote:
    >> >> On Thu, 05 Jun 2008 10:12:32 -0700, James Kimble wrote:
    >> >> > Yeah I'm sure this is a stupid question.

    >>
    >> >> > I've got a javascript source file with functions (creates a bar
    >> >> > graph) I want to call from inside an html table cell so that the
    >> >> > graph appears in the cell. I've tried a bunch of different things
    >> >> > but I'm not getting it. I'm a newbee to both html and javascript
    >> >> > so be kind.

    >>
    >> >> > Any example would be appreciated.

    >>
    >> >> > My current attempt looks like:

    >>
    >> [Code snipped]
    >>
    >> >> This is correct, though unexpected, behavior.

    >>
    >> >> If you call "document.write" WHILE THE PAGE IS LOADING, then it will
    >> >> kind of 'slip' stuff into your web page.

    >>
    >> >> However, you are calling it AFTER the page has loaded, which will
    >> >> REPLACE the contents of your page with the new information. Many
    >> >> folks consider document.write problematic at best recommend avoiding
    >> >> it.
    >> > Ok, but what would be the correct way to do this (ie. show the table
    >> > with the graph in it)?

    >>
    >> The correct way would be to use the DOM methods to create elements and
    >> insert them into the document, or to create the graph server-side.
    >>
    >> <URL:http://www.quirksmode.org/dom/intro.html>
    >>
    >> you might also get away with using innerHTML, but I have been getting
    >> away from that.

    >
    > Not big on examples are ya.....



    a) Since I can't see ANY of the code that actually draws your graph,
    there is no way that I could have provided an example.

    b) There was no "short" answer to your question and the long answer was
    "Learn about this topic." I provided two terms "DOM methods" and
    "innerHTML" with a link that would get you started.

    > I'm really just trying to throw something together. Getting it done in
    > the purest form of correctness is not required or even particularly
    > desirable because this is to be a rough demo. Not a finished product.


    It is possibly that using innerHTML would do what you would like, but
    again, without seeing the chart-rendering code I don't know.

    > So I guess I'll go to the book store and do a little reading. I do
    > appreciate your guidance but I was really just looking for a simple "do
    > this" type response to the snippet of code I posted.


    As much as I dislike it (and the problems it has) did you even look up
    the "innerHTML" that I mentioned?

    > Thank you anyway.....


    De Nada
     
    Jeremy J Starcher, Jun 9, 2008
    #11
  12. James Kimble

    James Kimble Guest

    On Jun 8, 4:42 am, "Tom de Neef" <> wrote:
    > "James Kimble" <> schreef in berichtnews:...
    >
    > > Yeah I'm sure this is a stupid question.

    >
    > There are no stupid questions. There are only stupid answers.
    >
    >
    >
    >
    >
    > > I've got a javascript source file with functions (creates a bar graph)
    > > I want to call from inside an html table cell so that the graph
    > > appears in the cell. I've tried a bunch of different things but I'm
    > > not getting it. I'm a newbee to both html and javascript so be kind.

    >
    > > Any example would be appreciated.

    >
    > > My current attempt looks like:

    >
    > > <head>
    > > <script language="JavaScript" src="bargraph.js"></script>
    > > <script language="JavaScript">
    > > function createBarGraph() {
    > > graph = new BarGraph("HorizBar");
    > > graph.values = "1000";
    > > document.write(graph.create());
    > > }
    > > </script>
    > > </head>
    > > <body onLoad="createBarGraph()">
    > > <table width="100%" border="0">
    > > <tr>
    > > <td>HPX40</td>
    > > <td>CUSTOMER DEFINED TEXT </td>
    > > <td>&nbsp;</td>
    > > </tr>
    > > <tr>
    > > <td>Plate Status:</td>
    > > <td><form name="f1" action="javascript:createBarGraph()"
    > > method="post"></td>
    > > <td>40.5KW</td>
    > > </tr>
    > > </table>
    > > </body>

    >
    > > This just displays my graph by itself. No other table items appear.

    >
    > Some suggestions:
    > <head>
    > <script type="text/JavaScript" src="bargraph.js"></script>
    > function createBarGraph() {
    > graph = new BarGraph("HorizBar");
    > graph.values = "1000";
    > return graph.create()
    > }
    > </script>
    > </head>
    >
    > Chech the <script> tag for its attributes
    > document.write removed. Its intention is to replace the current page. That
    > is not what you want. The function now returns the (html) string produced by
    > graph.create(). At least I guess that's what graph.create() will return.
    > But you need more: you want to place this text inside a table cell.
    > Conceptually, the html - as a string - would read like this:
    > '<td>'+createBarGraph()+'</td>'. You can make this happen if you can
    > identify the table cell. So, give it an ID, like
    > <table>
    > <tr>
    > <td> Plate Status:</td>
    > <td id=graphcell> </td>
    > <td>40.5KW</td>
    > </tr>
    > </table>
    > 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.
    >
    > Of course, you can combine these things and use
    > <body
    > onLoad="document.getElementById(graphcell).innerHTML=createBarGraph()">
    > and do without the extra function if you really want to push your code on
    > the track of unmaintainability.
    > Tom



    Thanks Tom (D). I appreciate your help! Unfortunately there are too
    many self appointed "PointyEars" on Usenet that just can't seem to
    realize that being an ass is easy. Being helpful, not so much.

    Of course anyone that would post their name with "PointedEars" in
    quotes, by definition, has got to be a bit of and idiot so I shouldn't
    be surprised. "PointedEars", take a pill....

    Thanks again,
     
    James Kimble, Jun 10, 2008
    #12
  13. James Kimble

    James Kimble Guest


    > > a) Since I can't see ANY of the code that actually draws your graph,

    > there is no way that I could have provided an example.


    I understand that

    > b) There was no "short" answer to your question and the long answer was
    > "Learn about this topic." I provided two terms "DOM methods" and
    > "innerHTML" with a link that would get you started.


    Right, but I wasn't looking for the long answer. I was looking for a
    simple example. A
    simple example was possible because one is posted above.

    > > I'm really just trying to throw something together. Getting it done in
    > > the purest form of correctness is not required or even particularly
    > > desirable because this is to be a rough demo. Not a finished product.

    >
    > It is possibly that using innerHTML would do what you would like, but
    > again, without seeing the chart-rendering code I don't know.


    An easier way was listed above.

    > > So I guess I'll go to the book store and do a little reading. I do
    > > appreciate your guidance but I was really just looking for a simple "do
    > > this" type response to the snippet of code I posted.

    >
    > As much as I dislike it (and the problems it has) did you even look up
    > the "innerHTML" that I mentioned?
    >


    No but I appreciate the suggestion and I will take a look at that
    method.

    > > Thank you anyway.....

    >
    > De Nad


    Not sure why this got so undy bunching. It was a simple question with
    a simple
    answer. I do appreciate the help though.
     
    James Kimble, Jun 10, 2008
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Williams
    Replies:
    2
    Views:
    1,184
    Jacob Yang [MSFT]
    Aug 12, 2003
  2. Beffmans
    Replies:
    1
    Views:
    5,464
    John Timney \(ASP.NET MVP\)
    Jul 8, 2005
  3. Rio
    Replies:
    4
    Views:
    1,250
  4. vitay
    Replies:
    8
    Views:
    575
    Stan McCann
    Nov 9, 2006
  5. srinivas
    Replies:
    0
    Views:
    978
    srinivas
    Nov 18, 2005
Loading...

Share This Page