PDA

View Full Version : checking for a layer using a variable?


x_goose_x
10-05-2002, 04:30 AM
Why is it that if I use

if (document.getElementById('mylayer3')) {

to test if a div is there it works no problem, but if I use a variable like so,

val = 3;
if (document.getElementById('mylayer'+val)) {

it doesn't work? I tried playing around with eval, but no luck. Any thoughts?

Graeme Hackston
10-05-2002, 05:06 AM
I don't know why yours doesn't work

val = "3"
element = ('mylayer').concat(val);
onload = function() {
if (document.getElementById(element)) {
alert('test')
}
}

Graeme Hackston
10-05-2002, 05:13 AM
Just playing with it. It works this way also

if (document.getElementById(('mylayer').concat(val))) {

Graeme Hackston
10-05-2002, 05:19 AM
I take that back, yours works to. It must have to happen onload.

x_goose_x
10-05-2002, 02:31 PM
Thats the thing. I'm using onload. But no prob, I found another way of accomplishing what I wanted to that is more user friendly.

Thnx