error on value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ddtpmyra
    Contributor
    • Jun 2008
    • 333

    error on value

    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

    Code:
    alert((document.getElementById('x').value)+
    (document.getElementById('y').value));
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

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

    kind regards

    Comment

    • ddtpmyra
      Contributor
      • Jun 2008
      • 333

      #3
      Originally posted by gits
      just make use of the parseInt() or parseFloat() methods for the values ...

      kind regards
      Thanks Gits your the best!

      and here's what I did to sum my two inbox.
      Code:
         alert(parseInt(document.getElementById('Organization').value)+parseInt(document.getElementById('Agencies').value));

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        no problem :) glad to hear you got it working ...

        kind regards

        Comment

        Working...