473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DHTML / Styles in JavaScript...error msgs.

I am trying to write a function that will centre a DIV-layer into the middle of the web browser screen. This is only for Internet Explorer. I keep getting and Invalid Argument error whenever I call the function (in the line oRef.style.left = ...).

I am brain dead! What's wrong with my code?

TIA..

function CentreOnScreen(LayerID)
{
var oRef = eval('document.all.'+ LayerID);
//alert(oRef +', '+ LayerID);
oRef.style.left = (screen.availWidth - oRef.style.width)/2;
oRef.style.right = (screen.availHeight - oRef.style.height)/2;
oRef.style.zIndex = 1;
}
Jul 23 '05 #1
2 1462


A. Nonymous wrote:

function CentreOnScreen(LayerID)
{
var oRef = eval('document.all.'+ LayerID);
Make that
var oRef = document.getElementById(LayerID);
if (oRef && oRef.style) {
oRef.style.left = (screen.availWidth - oRef.style.width)/2;
CSS properties are strings as for instance width is a number plus a unit
so if you really want to use style.width then you need to call parseInt
on it e.g.
oRef.style.left =
(screen.availWidth - parseInt(oRef.style.width)) / 2 + 'px';
however I guess you want
oRef.style.left =
(screen.availWidth - oRef.offsetWidth) / 2 + 'px';
oRef.style.right = (screen.availHeight - oRef.style.height)/2;


Same problems here.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Okay,

I think I figured it out!

1) I need parseInt() around the expression (availHeight - height/2)

2) There is no such attribute as obj.style.right. That should read obj.style.top.

3) The DIV-layer I'm using needed style="position: absolute" in the tag.
"A. Nonymous" <an*******@hotmail.com> wrote in message news:6M********************@giganews.com...
I am trying to write a function that will centre a DIV-layer into the middle of the web browser screen. This is only for Internet Explorer. I keep getting and Invalid Argument error whenever I call the function (in the line oRef.style.left = ...).

I am brain dead! What's wrong with my code?

TIA..

function CentreOnScreen(LayerID)
{
var oRef = eval('document.all.'+ LayerID);
//alert(oRef +', '+ LayerID);
oRef.style.left = (screen.availWidth - oRef.style.width)/2;
oRef.style.right = (screen.availHeight - oRef.style.height)/2;
oRef.style.zIndex = 1;
}
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Richard Silverstein | last post by:
I'm a member of a forum sponsored by jasc.com ( http://forums.jasc.com/ ) which uses Webboard software. I use Firefox 1.0 (final release) as my browser. When I used previous versions of FF I had...
2
by: mr_burns | last post by:
hi there, i would like a book that will explain concepts of javascript and dhtml instead of, for example, ten tutorials on how to do specific things in js or dhtml. ideally a book thats can...
3
by: unurban | last post by:
I have a javascript menu based off of unordered lists that only shows the subnav links when you click on the main nav links. is there a way to keep any subnav items open after you click on a link...
12
by: dan.vendel | last post by:
Hi, I know nothing about javascript, but quite a lot about regulat html and CSS. Have bumped into a problem that people in this fine congregation perhaps can help me with. I'm making a...
3
by: moondaddy | last post by:
I have some text in a page that when a certain even happens, I need to make it glow from black to red (through a spand of 1 second) pause for a few seconds, and then slowly change from red to black...
3
by: Mahmoud | last post by:
When I wrote the following code to create a dynamic table with styles associated with each row, it worked in Firefox. But when this was tried in IE, the result was a table with no styles that were...
1
by: sdonohue | last post by:
I am not very good at DHTML, but I have a set of links that use DHTML and they work :) But now the customer wants to have one of my DHTML links call a javascript function when it is clicked on. ...
0
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along...
2
by: Ross | last post by:
When I sometimes want to debug something on a browser without a firebug console, I have been using a textarea to which I can print stuff. So my HTML calls my big script file, and further down in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.