[object HTMLInputElement] shows instead of total

Hi guys, another lame question, Im sorry, but Ive been playing with this for a while and cant work out why this is happening.

I am trying to add some variables and display their contents in an input field. My code looks something like this:


var Num1 = document.getElementById('1stTotal');
var Num2 = document.getElementById('2ndTotal');
var Num3 = document.getElementById('3rdTotal');
var Num4 = document.getElementById('4thTotal');
var Num5 = document.getElementById('5thTotal');
				
var Total = Num1 + Num2 + Num3 + Num4 + Num5;
				
grandTotal.value = Total;

Now, this gives me [object HTMLInputElement] in the text field instead of the value. How do I need to structure this in order for it to work?

thanks again!

Hi,

Use value property of an object.

e.g.

var Num1 = document.getElementById('1stTotal').value;
var Num2 = document.getElementById('2ndTotal').value;
var Num3 = document.getElementById('3rdTotal').value;
var Num4 = document.getElementById('4thTotal').value;
var Num5 = document.getElementById('5thTotal').value;
				
var Total = Num1 + Num2 + Num3 + Num4 + Num5;
				
grandTotal.value = Total;

Thank You

thanks for the reply, but that just joins the strings together instead of adding the values and returning the sum.

Can anyone else help?

thanks

Then wrap all NumX into parseInt() function.

parseInt() didnt work but after digging around I found the Number() function which did the trick.

thanks