Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I reference elements in Layers in NN

Status
Not open for further replies.

martindavey

Programmer
Jan 2, 2000
122
GB
I have created several layers on my page.
In each layer is a form.
I am trying to reference the elements on those forms without success.
Example.

<body onLoad=&quot;document.layers.layer1.Page1.FirstName.focus();&quot;>

<layer id=&quot;layer1&quot;>
<form name=&quot;Page1&quot;>
<input type=&quot;text&quot; name=&quot;FirstName&quot;>
</form>
</layer>

This gives me the error:
document.layers.layer1.Page1 has no properties.

I've tried:
document.Page1.FirstName
document.layer1.FirstName
documents.layers.layer[&quot;layer1&quot;].Page1.FirstName
etc.

Any ideas??????


 
documents.layers[&quot;layer1&quot;].Page1.FirstName
 
Try this

document.getElementById('name').

:)
 
iza's solution works in just Netscape. Mine is cross browser compatible. Use whatever you need.
 
TGWW, your &quot;cross browser&quot; is only for IE and Netscape6.

to martindavey:
REAL cross browser should combine both
document.getElementById('name')
and
documents.layers[&quot;layer1&quot;].Page1.FirstName

to use this you should also put your <layer> inside <div>.

Andrew | starway@mail.com
 
i don't really think &quot;layer&quot; is a cross browser element - or is it ??
 
>>i don't really think &quot;layer&quot; is a cross browser element - or is it ??

No, it isn't. But it's the only way to maintain control over &quot;layers&quot; of content in NN4.x
Unfortunately...

Andrew | starway@.mail.com
 
Thanks for the help guys BUT...
Please confirm that I'm a complete stupid arse...
I've tried the following 3 commands as an experiment:

1. ...onLoad=&quot;document.getElementById('FirstName').focus();&quot;>

2. ...onLoad=&quot;documents.layers[&quot;layer1&quot;].Page1.FirstName.focus();&quot;>

3. ...onLoad=&quot;documents.layers.layer1.Page1.FirstName.focus();&quot;>

I get the following 3 errors respectively:

1. document.getElementById is not a function.

2. syntax error.
documents.layers[
................^

3.documents is not defined.

Sorry for acting the fool!!!
 
OK martindavey, here's some info for you:

1. Concerning your last posts:
a) As far as I know, getElementById functoin was implemented only in Netscape6, so it's no wonder that you get an error.
b) >> syntax error: documents.layers[
&quot;document&quot; should be without &quot;s&quot; at the end.

2. About your problem (remember what all this started from?):
This is taken from Netscape's Developer Guide:
&quot;Each layer object contains its own document object.&quot;

So, in order to access element placed on a layer you have to use this expression:
document.[&quot;layername&quot;].document.<element>

where <element> is an element that you want to access, like Page1.FirstName that you asked about. Sounds illogically a little bit, but that's the way it is.

Remember that LAYER tag is for absolute and ILAYER is for relative positioning only.
And that they work only in NN4.x!
As I stated before, in order to create script compatible with Netscape6 you should duplicate everything using
document.getElementById('name')
Hope it will solve your problem at last!

Andrew | starway@mail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top