Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-07-2012, 02:52 AM   PM User | #1
Drew012
New Coder

 
Join Date: Jul 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Drew012 is an unknown quantity at this point
Smile Update HTML table/javascript variable as user inputs them?

Code:
<table id="totals">
       <tbody>
                <th scope="col">Social </th>
                <td id = "hello">&nbsp;</td>
        </tbody>    
</table>  

<script>
//this defines my four variables
var nSocial1, nSocial2, nSocial3, nSocial;
// this pulls the value from certain questions ("Q1") etc.
nSocial1 = parseInt(document.getElementById("Q1").value);
nSocial2 = parseInt(document.getElementById("Q9").value);
nSocial3 = parseInt(document.getElementById("Q17").value);
nSocial = nSocial1 + nSocial2 + nSocial3;

document.getElementById("hello").innerHTML = nSocial;

</script>

The table td id ="hello" is successfully filled with the javascript var "nSocial". However, as you can see, nSocial is composed of nSocial1+nSocial2+nSocial3. If I assign each of these to 10, it will successfully add them together to get 30. However, I want them to be set to 0 at default and to change/update automatically as the user inputs a value that can be determined by the corresponding ("Q").
Drew012 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:25 PM.


Advertisement
Log in to turn off these ads.