473,287 Members | 1,395 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,287 software developers and data experts.

JavaScript not working.

I have an ASP.net page where I am trying print the page directly from a
printer. The only way I can figure out how to do this is in Javascript with
PrintDomTree.

The problem is that I don't get anything back when using a getElementByID.
It is null. The ID is there.

Here is the javascript:

****************************
function printDOMTree(destinationWindow)
{
// Use destination window to print the tree. If destinationWIndow is
// not specified, create a new window and print the tree into that
window

alert("Inside printDOMTree");
var domElement = document.getElementById('MainTable');
if (domElement == null)
alert("domElement == null");
else
alert ("domElement != null");
************************************************

I get the alert back that says domElement is null.

Here is the tag:

<DIV ID="MainTable">

And you can see it when you viewsource.

What am I missing?

Thanks,

Tom
May 17 '06 #1
2 1048
Is this JS before the body tag or at the end of page?
Put it at the end, this way your whole document will be loaded before you
access any tags.

http://www.netomatix.com

"tshad" <ts**********@ftsolutions.com> wrote in message
news:uz******************@TK2MSFTNGP05.phx.gbl...
I have an ASP.net page where I am trying print the page directly from a
printer. The only way I can figure out how to do this is in Javascript
with PrintDomTree.

The problem is that I don't get anything back when using a getElementByID.
It is null. The ID is there.

Here is the javascript:

****************************
function printDOMTree(destinationWindow)
{
// Use destination window to print the tree. If destinationWIndow is
// not specified, create a new window and print the tree into that
window

alert("Inside printDOMTree");
var domElement = document.getElementById('MainTable');
if (domElement == null)
alert("domElement == null");
else
alert ("domElement != null");
************************************************

I get the alert back that says domElement is null.

Here is the tag:

<DIV ID="MainTable">

And you can see it when you viewsource.

What am I missing?

Thanks,

Tom

May 17 '06 #2
This was my mistake.

I just found that it was print the other message. Brain Fade for a moment.

Thanks,

Tom
"Winista" <na*********@hotmail.com> wrote in message
news:eQ*************@TK2MSFTNGP04.phx.gbl...
Is this JS before the body tag or at the end of page?
Put it at the end, this way your whole document will be loaded before you
access any tags.

http://www.netomatix.com

"tshad" <ts**********@ftsolutions.com> wrote in message
news:uz******************@TK2MSFTNGP05.phx.gbl...
I have an ASP.net page where I am trying print the page directly from a
printer. The only way I can figure out how to do this is in Javascript
with PrintDomTree.

The problem is that I don't get anything back when using a
getElementByID. It is null. The ID is there.

Here is the javascript:

****************************
function printDOMTree(destinationWindow)
{
// Use destination window to print the tree. If destinationWIndow is
// not specified, create a new window and print the tree into that
window

alert("Inside printDOMTree");
var domElement = document.getElementById('MainTable');
if (domElement == null)
alert("domElement == null");
else
alert ("domElement != null");
************************************************

I get the alert back that says domElement is null.

Here is the tag:

<DIV ID="MainTable">

And you can see it when you viewsource.

What am I missing?

Thanks,

Tom


May 17 '06 #3

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

Similar topics

10
by: VictorG | last post by:
Hello, I am new to JS and am trying to add some HTML into a JS function. So that when called the script as well as the HTML will be invoked. Is there some type of embed mechanism, sort of the...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
1
by: Muhammad Abdullah | last post by:
Hi am having some problems with the javascript confirm. i have it working fine on one page and it doesnt even pop up at the other. The code on the working page is, private void...
1
by: den2005 | last post by:
Hi everybody, I am confused and still looking why this codes is not working. Can anyone notice or know why this code is not working? Thanks in advance. Code working: <form id="form1"...
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
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: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.