...

View Full Version : Adding 1 to a variable



jozps2
01-14-2004, 06:49 AM
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

Willy Duitt
01-14-2004, 07:02 AM
Try this:

document.write(" = " + (passedData[o]+1)+"<br />");

.....Willy

jozps2
01-14-2004, 07:10 AM
thx for the reply....but unfortianately i still get the same result :(

jozps2
01-14-2004, 07:28 AM
also btw, the variable does have a numerical value....just to clear that up

glenngv
01-14-2004, 07:37 AM
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--



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum