Guray Alsac

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromGuray Alsac
ToMe
Subjectmultiple generic dragable layers
Date6 October 2005 19:03
Tarquin,

First of all, thank you for your javascript libraries. I'm new to the
language but really enjoyed your site.

I am using your generic dragable layer script to produce multiple dragable
layers on a webpage. The viewer moves them around, and then I have a form
with a submit button that I want to have run some javascript to submit the
locations of all the various dragable layers. But I am struggling just with
accessing the 'top' attribute of one of the layers.

I modified the script so that the createDragableLayer() function writes to
the document not just '<layer left=...' but '<layer id=layer' + layerCount +
'left=...', where layerCount gets incremented after every call. How can I
then access the top attribute of the first layer created?

I've tried things ranging from
document.getElementById('layer0').getAttribute('top')
to
document.layer0.top
to
window.layer0.top

The errors are usually just "window.layer0 has no properties" depending on
how I try to access it. I'm running Firefox 1.0.6. Unfortunately, I am
writing questions for an online homework collection system at our university
so you would not be able to see the page without a login. If you absolutely
need to see the code to help me I can see what I can do.

Any help is appreciated.

Cheers,
Guray
FromMe
ToGuray Alsac
SubjectRe: multiple generic dragable layers
Date6 October 2005 20:58
Guray,

> I modified the script so that the createDragableLayer() function writes to
> the document not just '<layer left=...' but '<layer id=layer' + layerCount +
> 'left=...', where layerCount gets incremented after every call. How can I
> then access the top attribute of the first layer created?

almost there .. but
the <layer tags are only used by Netscape 4. The other browsers use the
<div tag

document.write( '<layer id="layer' + layerCount +'" left....
document.write( '<div id="layer' + layerCount +'" style....

> I've tried things ranging from
> document.getElementById('layer0').getAttribute('top')

you are mixing the methods here. This will work in the maximum number of
browsers (even the old ones, if you care):

var top = 0, left = 0;
if( document.getElementById ) {
    top = parseInt(document.getElementById('layer0').style.top);
    left = parseInt(document.getElementById('layer0').style.left);
} else if( document.all ) {
    top = parseInt(document.all['layer0'].style.top);
    left = parseInt(document.all['layer0'].style.left);
} else if( document.layers ) {
    top = document.layers['layer0'].top;
    left = document.layers['layer0'].left;
}


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromGuray Alsac
ToMe
SubjectRe: multiple generic dragable layers
Date7 October 2005 17:13
Worked like a charm. Thanks for the prompt response! --Guray
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.