Java script code to add sum... check plz

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
naveendk.55
Forum Newbie
Posts: 24
Joined: Tue Aug 16, 2011 10:13 am

Java script code to add sum... check plz

Post by naveendk.55 »

I am trying to add values from 6 text boxes and display its sum automatically in 7th text box. This is not working. Please help.


Code: Select all


function calculate_a() {
var a = document.getElementById('Para_A_A1_score').value ;
var b = document.getElementById('Para_A_A2_score').value ;
var c = document.getElementById('Para_A_A3_score').value ;
var d = document.getElementById('Para_A_A4_score').value ;
var e = document.getElementById('Para_A_A5_score').value ;
var f = document.getElementById('Para_A_A6_score').value ;
var g = (a+b+c+d+e+f) ;
document.audit_billing_IE.product_name4.value = g ;
}

Code: Select all


[text] Below is the html form code that should automatically display the total value without clicking on any submit or send button 
 [/text]

<tr>
                    <td> Parameter A </td> 
                    <td colspan='3'> <input type="text" name="product_name4" id="product_name4" onchange="calculate_a(this);" /> </td>
                </tr>

User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Java script code to add sum... check plz

Post by VladSun »

naveendk.55 wrote:I am trying to add values from 6 text boxes and display its sum automatically in 7th text box. This is not working.
"Not working" doesn't mean anything ... Please, be more descriptive next time.


Try subtracting zero from each, thus converting to integer.

Code: Select all

var a = document.getElementById('Para_A_A1_score').value - 0;
var b = document.getElementById('Para_A_A2_score').value - 0;
...
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply