Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to use a javascript var in an HTML table?

    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.

    Code:
    <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!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,514
    Thanks
    77
    Thanked 4,379 Times in 4,344 Posts
    Code:
    <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.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •