PDA

View Full Version : How to use a javascript var in an HTML table?



Drew012
07-07-2012, 12:21 AM
I have a javascript variable that is universal. To sum up my problem, the user can change the value of the var A. They do this because var A = var B + C.
The user can change var B and C. When I set it up so the user can select B and C, and then I alert(A); everything works and they are added together.

Here is my problem. I want to be able to change B and C but have A update automatically in a HTML table.



<table id=totals>
<tbody>
<th scope="col"> Random Table Column Here </th>
<td> <!-- This is where I want var A to update --> </td>
</tbody>
</table>


Any ideas on how I can do this?
I must use this exact HTML format because I am using a plugin that automatically creates a graph based off a HTML table styled this way. Thanks for the help!

Old Pedant
07-07-2012, 01:30 AM
<table id=totals>
<tbody>
<th scope="col"> Random Table Column Here </th>
<td id="fromzelowishik">&nbsp;</td>
</tbody>
</table>
...

<script type="text/javascript">
... various code ??? ...

...
var A = Number(B) + Number(C);
document.getElementById("fromzelowishik").innerHTML = A;
...

... various code ??? ...
</script>

Please note that "fromzelowishik" and "FromZelowishik" are not the same. (In other words, use any ID you want, but make sure you spell it exactly the same in all usages.)