473,385 Members | 1,387 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,385 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 1053
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...
1
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.