adding vars not text strings

Discussion in 'JavaScript' started by GoldDog, Jun 16, 2005.

  1. #1
    How can I get my function to recognize this...

    subt = document.getElementById('subT').innerHTML;

    ...as a numeric value rather than a text string?

    My math...

    ty = 23;
    subt = document.getElementById('subT').innerHTML;
    cost = ty+subt;
    document.getElementById('subT').innerHTML = cost;

    ...does not work. It rewrites 'subT' as a text string, rather than a computed value.

    thanks!
     
    GoldDog, Jun 16, 2005 IP
  2. gumape

    gumape Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    var num = parseFloat (subt);

    More info: parseFloat
     
    gumape, Sep 15, 2009 IP