PDA

View Full Version : Position of HTML controls


frank001
05-11-2005, 06:41 PM
Hi,

How can I access the coordinates of the browser rendered HTML controls?
I tried HTML DOM from JScript, but those properties gave nothing back.

Steps:
1. Server generates a html source and send to the browser.
2. Browser renders html source and makes the site.
3. JScript is running in the site and trying to get coordinates of the HTML controls (radio buttons, text fields, ... )

for example:

var Element = document.getElementById( "1" );
alert(Element.style.left); // shows nothing
alert(Element.style.top); // shows nothing

or

var table = document.getElementById('table');
var row = table.rows[1];
var cell = row.cells[2];
alert(cell.width); // shows nothing


These properties are empty!
Why?
How can I get these values?

Thanks,
Frank

MikeFoster
05-11-2005, 09:09 PM
Hi Frank, welcome to CodingForums!

First, have a look at this (http://cross-browser.com/talk/wheres_my_style.php).

Tip: Don't use a number as an ID. I often use IDs like this: text1, text2, radio1, radio2, etc.

Feel free to ask more questions :)

glenngv
05-12-2005, 05:32 AM
You may be looking for offsetLeft, offsetTop and offsetWidth. Search for these in CF and you'll find many results.

frank001
05-12-2005, 06:16 PM
Thanks for your answers.

I tried offsetXXX properties.
It works fine.

:)
Frank