• Advertisement
Sign in to follow this  

[web] Using javascript, how to output total for variable to an already made table?

This topic is 4874 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, using javascript I want to output the value of a calculation into an existing table. eg <head>
  <script language="javascript">
    function getSum() {
       return 5+ 5; //an example
    }
  </script>
</head>
<body>
  <table>
    <tr>
      <td>abc</td>
      <td>def</td>
    </tr>

    <tr>
      <td>Total:</td>
      <td>(I want to put javascript value here)</td>
    </tr>
  </table>
</body>


How would I put a value there?, that is the bottom right field of the table. Also I need to be able to dynamically change the value that is set there, as , say the user enters different numbers in a field(that I havent shown above) so I can constantly keep updating that total. THanks

Share this post


Link to post
Share on other sites
Advertisement
yeah, but say something else updates what the sum would be, how would i get it to recall the document.write(getsum())?

thanks

Share this post


Link to post
Share on other sites
DHTML:
Let's say you have a bit of text you want to change.
You apply the ID parameter to the tag you want to play with; for example:
<p id="changing">This is text</p>
<script>
document.getElementById("changing").innerText = "Hello";
</script>


Would change the text in the <p> tag. You can also specify document.getElementById("changing").innerHTML to change it.
For a rolling demo; Here's my "placeholder" on my website.

Share this post


Link to post
Share on other sites
What's the difference between .innerText and .innerHTML, if any?

Share this post


Link to post
Share on other sites
innerText removes HTML tags. If you edit the .innerHTML property, you will kill any HTML in the object, and just return and text. However, innerHTML is the actual HTML of an object. Try experimenting.

I think you're supposed to use the <span> tag instead of the <p> tag because you can't have paragraphs in tables (one block element inside another)

Share this post


Link to post
Share on other sites
Quote:
Original post by evolutional
Ben, your website killed my brain [wow]

[grin]
Nothing like some Radiohead nonsense. Hey, it needed *something* to be there...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement