#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Location
    UK
    Posts
    59
    Rep Power
    13

    javascript variable problem


    Hi all,

    Can someone please tell me why this:

    pxl = parseInt(document.MM_Time[0][1].values[i-1] + tmp)

    concatenates as opposed to adds? E.g. the left value is -100 (I've checked) and the value of tmp is 9, the result should be -91 but I get -1009

    Any help greatly appreciated.
    Torrent
    www.ski-info-online.com

    ...silently carving the soft deep powder...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    13
    Did you try:

    alert(typeof document.MM_Time[0][1].values[i-1]);

    If either of the values in the parentheses is a string, both will be concatenated before parseInt returns an integer value. This might work:

    pxl = Number(document.MM_Time[0][1].values[i-1]) + tmp;

    If tmp is a string, run that through the Number() constructor too.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Location
    UK
    Posts
    59
    Rep Power
    13

    Thumbs up


    You the man!
    Thanks a lot for your help.
    It's working fine using the number constructor
    Torrent
    www.ski-info-online.com

    ...silently carving the soft deep powder...

IMN logo majestic logo threadwatch logo seochat tools logo