By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,697 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,697 IT Pros & Developers. It's quick & easy.

error on value

ddtpmyra
100+
P: 333
I have input box and has a id with value of the following
x=12
y=12

and when it display the sum of two it shows '1212' . Looks like I did was to add the string not the value. How do you do proper mathematical calculation

Expand|Select|Wrap|Line Numbers
  1. alert((document.getElementById('x').value)+
  2. (document.getElementById('y').value));
Nov 13 '09 #1

✓ answered by gits

just make use of the parseInt() or parseFloat() methods for the values ...

kind regards

Share this Question
Share on Google+
3 Replies


gits
Expert Mod 5K+
P: 5,390
just make use of the parseInt() or parseFloat() methods for the values ...

kind regards
Nov 13 '09 #2

ddtpmyra
100+
P: 333
@gits
Thanks Gits your the best!

and here's what I did to sum my two inbox.
Expand|Select|Wrap|Line Numbers
  1.    alert(parseInt(document.getElementById('Organization').value)+parseInt(document.getElementById('Agencies').value));
Nov 13 '09 #3

gits
Expert Mod 5K+
P: 5,390
no problem :) glad to hear you got it working ...

kind regards
Nov 13 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.