Click to See Complete Forum and Search --> : accessing an object as variable


shumway
11-05-2003, 07:54 AM
Im trying to move an image within an iframe. The problem is that I have the id of the iframe in a variable and I cant get it to work.



This works great:
Games.document.all['DivBorderTR'].style.left = 100;

But this doesnt:
$module = 'Games';
getElementById( $module ).document.all['DivBorderTR'].style.left = 100;

(I have several iframes that looks similar and this code is supposed to work for any iframe-id given in $module.)

You can look at it at: www.battlesite.com/henrik/battlesite2 (just press login-button - no userid or password required)

gil davis
11-05-2003, 08:54 AM
A JavaScript identifier, or name, must start with a letter or underscore ("_"); subsequent characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase).
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/guide/ident.html#1008333

shumway
11-05-2003, 11:17 AM
Thanks for your answer gil davis but im not sure I follow you. The id "Games" do follow the rules and variables starts with $-signs dont they - at least everything else works fine with that.

Khalid Ali
11-05-2003, 11:38 AM
Actually you can use $sign to begin a variable name.

I think in your code you are not using document before getEle,,,,
getElementById( $module )
should be
document.getElementById( $module )
and instead of using document.all[] use document.getElementById