Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding 1 to a variable

    how do i add a number to a variable?? for example i have document.write(" = " + passedData[o]+"<br />"); and i want to add 1 to passedData[o] so that if passedData[o] was equal to 1 the new number would be 2



    this is what i have right now:
    document.write(" = " + passedData[o]+(+1)+"<br />");

    but that gives me 1+1= 11 instead of 1+1= 2

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this:
    Code:
    document.write(" = " + (passedData[o]+1)+"<br />");
    .....Willy

  • #3
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thx for the reply....but unfortianately i still get the same result

  • #4
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    also btw, the variable does have a numerical value....just to clear that up

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    are you really sure that passedData[o] contains a number? But wait, is that a letter o or zero -- passedData[o]?

    Does this simple code work for you?
    var x=2;
    alert('--'+(x+1)+'--'). //should alert --3--


  •  

    Posting Permissions

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