...

View Full Version : getElementById Method



dr_bay
09-19-2005, 11:55 PM
Any idea how I can get this display one number higher than it would display, i.e. if "which" is equal to 4 I want it to display 5. Any help will be appreciated.



function changepic(which)
{
var goodnum = which;
document.img.src = pic[goodnum];
document.getElementById('imgText').innerHTML = which;
}

Image <span id='imgText'>#</span> of 11

Pyth007
09-20-2005, 12:09 AM
If I understand your problem correctly, the problem is that "which" is a string and say 'which + 1' just concatinates '1' to the end of the string. You can quickly convert a string to a number by doing some arithmetic operation on it (aside from addition) without changing the actual value. Any of the following should work:

1) (which *1) + 1
2) (which / 1) + 1
3) (which - 0) + 1
4) (+which) + 1

dr_bay
09-20-2005, 01:41 AM
That did it. Thank you very much. :D

CrAzY_J
09-20-2005, 02:54 AM
or just use eval()

glenngv
09-20-2005, 04:59 AM
The most appropriate way is by using Number(), parseInt() or parseFloat() method.


Number(which) + 1



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum