View Full Version : getElementById Method
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.
var goodnum = which;
document.img.src = pic[goodnum];
document.getElementById('imgText').innerHTML = which;
Image <span id='imgText'>#</span> of 11
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
09-20-2005, 01:41 AM
That did it. Thank you very much. :D
09-20-2005, 02:54 AM
or just use eval()
09-20-2005, 04:59 AM
The most appropriate way is by using Number(), parseInt() or parseFloat() method.
Number(which) + 1
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.