473,573 Members | 2,814 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.getEle mentById comes out NULL help!

Hi,
I'm back again. Basically i'm trying to draw a box over an image which
is turning out to be a nightmare. The problem i'm getting at the moment
is that i'm creating a line with <div which works when it's not hidden
but I need to be able to make it hidden so I can use layers to show all
when it finished drawing to make it smoother. This is how some other
scripts are doing it that i've seen. So i've got it drawing a line and I
need getElementById to pick out the layer but it's only picking out NULL
with the one i've got enabled below. I've tried the others but they just
come out as errors. I need to get top2 which is the <div line to show
itself but I can't seem to reference it by getElementById. I use linux
mozilla so i need it working in mozilla as well as windows that's why
i'm using getElementById. My code is below any ideas anyone?

<html>
<head>
<script language="JavaS cript" type="">
document.onmous edown = onmousedown;
var netscape = (document.layer s) ? 1:0;
var goodIE = (document.all) ? 1:0;
var netscape6 = (document.getEl ementById && !document.all) ? 1:0;
var height = 100;
var width = 100;
var left = 50;
var top = 60;
var visible = false;

var name = 'secondtop';

str = '<div id="' + name +
'" style="position :absolute; overflow:none; left:' + left +
'px; top:' + top + 'px; width:' + width + 'px; height:' +
height +
'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') +
'"><img name="left" src="/asdd/pixel.gif" border="1"></div>';

document.writel n(str);

var layer;
//layer = document.getEle mentById("' + name + '").style;
if(document.get ElementById) {
//var show = document.getEle mentById;
//document.getEle mentById.(secon dtop) = visible;
var name = 'top2'
//layer = eval('document. getElementById( "' + name + '").style');
layer = document.getEle mentById("' + name + '");
//layer = eval('document. all.' + name + '.style');
//layer = document.layers[name];
alert("First" + layer);
}
else if(document.all ) {
//return document.all[eN];
alert("Second") ;
}
else {
alert("Third");
//return null;
}

//layer.visibilit y = "visible";
layer.visibilit y = "show";

alert("hello");
function onmousedown(e)
{
document.writel n("hello");
}

</script>
</head>
<body bgcolor="FFFFFF ">

<img border="1" src="iecadaptor .jpg">

<div id="top2" style="position :absolute; width:308px; height:1px;
z-index:1; left: 29px; top: 23px; overflow: visible; visibility: hidden;
background-color: black; layer-background-color: black; border: 1px none
#000000"></div>

</body>
</html>

Thanks

Gary
Jul 20 '05 #1
2 20924
On Tue, 02 Mar 2004 19:36:44 +0000, Gary Mayor <ga**@abertron. co.uk> wrote:
I'm back again. Basically i'm trying to draw a box over an image which
is turning out to be a nightmare. The problem i'm getting at the moment
is that i'm creating a line with <div which works when it's not hidden
but I need to be able to make it hidden so I can use layers to show all
when it finished drawing to make it smoother. This is how some other
scripts are doing it that i've seen. So i've got it drawing a line and I
need getElementById to pick out the layer but it's only picking out NULL
with the one i've got enabled below. I've tried the others but they just
come out as errors. I need to get top2 which is the <div line to show
itself but I can't seem to reference it by getElementById. I use linux
mozilla so i need it working in mozilla as well as windows that's why
i'm using getElementById. My code is below any ideas anyone?
The problem is that you're trying to access parts of a document that the
browser hasn't begun to parse yet. Place the code after the parts of the
document it is trying to access if the script must execute immediately.
You'll also probably have to close the output stream before accessing the
generated HTML. You might even need to use two separate SCRIPT elements;
it depends when the browser parses generated content.
<script language="JavaS cript" type="">
From your previous thread:

Don't do that. The type attribute should be used to specify the scripting
language, not language (it is deprecated).

<script type="text/javascript">

is the correct way to write the tag (with optional src and defer
attributes).
var netscape = (document.layer s) ? 1:0;
var goodIE = (document.all) ? 1:0;
var netscape6 = (document.getEl ementById && !document.all) ? 1:0;


Don't do that, either. There should not be any need to know the browser,
and detection by inference doesn't work anyway. Use feature detection, not
browser detection.

[snipped code]

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
Michael Winter wrote:
On Tue, 02 Mar 2004 19:36:44 +0000, Gary Mayor <ga**@abertron. co.uk> wrote:
I'm back again. Basically i'm trying to draw a box over an image which
is turning out to be a nightmare. The problem i'm getting at the
moment is that i'm creating a line with <div which works when it's not
hidden but I need to be able to make it hidden so I can use layers to
show all when it finished drawing to make it smoother. This is how
some other scripts are doing it that i've seen. So i've got it drawing
a line and I need getElementById to pick out the layer but it's only
picking out NULL with the one i've got enabled below. I've tried the
others but they just come out as errors. I need to get top2 which is
the <div line to show itself but I can't seem to reference it by
getElementById. I use linux mozilla so i need it working in mozilla as
well as windows that's why i'm using getElementById. My code is below
any ideas anyone?

The problem is that you're trying to access parts of a document that the
browser hasn't begun to parse yet. Place the code after the parts of the
document it is trying to access if the script must execute immediately.
You'll also probably have to close the output stream before accessing
the generated HTML. You might even need to use two separate SCRIPT
elements; it depends when the browser parses generated content.
<script language="JavaS cript" type="">

From your previous thread:

Don't do that. The type attribute should be used to specify the
scripting language, not language (it is deprecated).

<script type="text/javascript">

is the correct way to write the tag (with optional src and defer
attributes).
var netscape = (document.layer s) ? 1:0;
var goodIE = (document.all) ? 1:0;
var netscape6 = (document.getEl ementById && !document.all) ? 1:0;

Don't do that, either. There should not be any need to know the browser,
and detection by inference doesn't work anyway. Use feature detection,
not browser detection.

[snipped code]

Mike

Cheers Mike I used a function and called the show layer from a link and
it worked so it's the fact it hasn't executed the html yet as your
saying. I will change it so the javascript is after the html. I thought
it executed all javascript first but it doesn't. I've changed that
javascript call. Thanks a lot I can carry on now. I'm a perl programmer
having to learn javascript. It's great Cheers
Jul 20 '05 #3

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

Similar topics

6
6829
by: David List | last post by:
I'm having a problem using different properties of the document object in the example javascripts in my textbook with browsers that identify themselves as using the Mozilla engine. One example of these problems is using document.layers. I have Google'd for examples of how to use the document object specifically with Mozilla, but I cannot find...
6
46553
by: John Ramsden | last post by:
.... when the id 'junk' doesn't exist anywhere in the document, instead of returning 'object'?! I am using Javascript for a drop-down menu, slightly adapted from one by Angus Turnbull (see http://javascript.internet.com and http://gusnz.cjb.net, not that this is probably relevant but it deserves a plug ;-), on Internet Explorer...
3
9820
by: Catherine Lynn Smith | last post by:
I am creating a webpage with dhtml <DIV> layers and I want a link on one layer to modify the content on another but I seem to keep running into errors. Basically I create a layer in the middle of the screen that initially comes up with a gif image of a house: <!-- start "house" layer definition for center of screen --> <DIV id="house"...
12
10142
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical scrollbar, you get the height of the entire document, screwing up any chance of centering a window in the browser using these values. Is there a...
20
6946
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt = document.getElementById('hometab'); Has anyone ever seen anything like this before, or am I dreaming?
5
4423
by: HopfZ | last post by:
I made two shortcut functions for document.getElementById as: function EBI2(id){return document.getElementById(id)}; var EBI3 = document.getElementById; But EBI3 don't work. EBI2('myText'); //works EBI3('myText'); //unexpected error
19
4330
by: vunet.us | last post by:
Hello, My AJAX application paints data into about 500 cells with unique ID every 10 seconds. I am using document.getElementById() to find the right cell. However, I have noticed that document.getElementById() in IE is freezing the browser for about 1 second unlike Firefox. Can anyone suggest any speed improvements for painting data into a...
2
3900
by: vegetable21 | last post by:
Hi, I'm relatively new to JavaScript, but not to programming. I'm trying to get a table to expand and collapse within a cell of my master table. However i want to collapse all the other open tables when i expand a new one. I'm nearly there but i get an error that i can't seem to shake. Firefox show me the error as the following: Error:...
7
8089
by: sunny1009 | last post by:
Hi Guys, Can you please check this code and see whats wrong with it?? I am getting document.all.style is null or not an object error. Any help will be really appreciated. Thanks Code function toggleDiv(id,flagit) {
0
8027
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8202
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7788
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8066
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6421
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5594
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3733
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3733
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2216
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.