Results 1 to 2 of 2

Thread: JS Help

  1. #1
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default JS Help

    Ok,

    I have this code, which is meant to add something on to the value currently displayed.

    Heres the code so far:
    HTML Code:
    function calc(hcs)
    {
    try{
     var cur = document.getElementById("calcscreen").innerHTML;
      cur = cur+hcs;
       document.getElementById("calcscreen").innerHTML = cur;
       }
       catch(err)
       {
       alert(err);
       }
    }
    function cls()
    {
    document.getElementById("calcscreen").innerHTML = 0;
    }
    Whats going wrong is that if we use the calc(2.0); function, if the initial display was 0 it would become

    02

    Then if we do again it would become

    022

    I think its making the variables string and as such, not adding correctly, if this is the case, does anyone have the code to turn them back into integer/single?

    Thanks for any help =]
    Last edited by MrCraig; 17-01-2008 at 05:48 PM.
    Coming and going...
    Highers are getting the better of me

  2. #2
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Sorry to double post,

    But does anyone know a way to get round this error?
    Coming and going...
    Highers are getting the better of me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •