473,548 Members | 2,593 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 20921
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
6828
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
46550
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
9819
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
10134
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
6934
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
4419
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
4323
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
3896
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
8087
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
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7707
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. ...
1
7466
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
7803
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
5082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1926
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
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.