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

document.body.onclick not working in script

I am trying to build a custom control to wrap my smart navigation
implimention (not microsofts 'cause it has problems)

The follow code works fine when the onclick and onload events are defined in
the Body tag. However, when I try to set them in Javascript code, I get
errors. What am I doing wrong???
**********THIS WORKS ************
<html>
<head>
<script>
function doOnClickBody() {
document.getElementById("hdnScrollTop").value =
document.body.scrollTop;
}

function doOnLoadBody() {
document.body.scrollTop = document.getElementById("hdnScrollTop").value;
}
</script>
</head>
<body onClick="doOnClickBody();" onLoad="doOnLoadBody();">

<form id="myFromId" runat="server">
<input type="hidden" id="hdnScrollTop" runat="server" />
</form>
</body>
</html>
***********THIS DOES NOT WORK ***************

<script language="javascript">
function doOnClickBody() {
document.getElementById("<%=Me.hdnScrollTop.Client Id%>").value =
document.body.scrollTop;
}

function doOnLoadBody() {
document.body.scrollTop =
document.getElementById("<%=Me.hdnScrollTop.Client Id%>").value;
}
document.body.onclick = doOnClickBody(); //CAUSES ERROR
document.body.onload = doOnLoadBody(); //CAUSES ERROR
</script>

<body MS_POSITIONING="FlowLayout" >
<form id="Form1" method="post" runat="server">
<input type="hidden" id="hdnScrollTop" runat="server" NAME="hdnScrollTop">
</form>
</body>
Nov 18 '05 #1
2 4416
<script language="javascript">
function doOnClickBody() {
//do something
}

function doOnLoadBody() {
//do something
}
document.onclick = doOnClickBody;
window.onload =doOnLoadBody;
</script>

should work in both IE and mozilla.

Karl

"Earl Teigrob" <Ea*********@discussions.microsoft.com> wrote in message
news:13**********************************@microsof t.com...
I am trying to build a custom control to wrap my smart navigation
implimention (not microsofts 'cause it has problems)

The follow code works fine when the onclick and onload events are defined in the Body tag. However, when I try to set them in Javascript code, I get
errors. What am I doing wrong???
**********THIS WORKS ************
<html>
<head>
<script>
function doOnClickBody() {
document.getElementById("hdnScrollTop").value =
document.body.scrollTop;
}

function doOnLoadBody() {
document.body.scrollTop = document.getElementById("hdnScrollTop").value;
}
</script>
</head>
<body onClick="doOnClickBody();" onLoad="doOnLoadBody();">

<form id="myFromId" runat="server">
<input type="hidden" id="hdnScrollTop" runat="server" />
</form>
</body>
</html>
***********THIS DOES NOT WORK ***************

<script language="javascript">
function doOnClickBody() {
document.getElementById("<%=Me.hdnScrollTop.Client Id%>").value =
document.body.scrollTop;
}

function doOnLoadBody() {
document.body.scrollTop =
document.getElementById("<%=Me.hdnScrollTop.Client Id%>").value;
}
document.body.onclick = doOnClickBody(); //CAUSES ERROR
document.body.onload = doOnLoadBody(); //CAUSES ERROR
</script>

<body MS_POSITIONING="FlowLayout" >
<form id="Form1" method="post" runat="server">
<input type="hidden" id="hdnScrollTop" runat="server" NAME="hdnScrollTop">
</form>
</body>

Nov 18 '05 #2
This ended up being strictly a timing issue. Objects where not created or at
leasts finished being created when I was tring accessing them. Using the
window.setTimeout functionfixed all my problems...

Earl

"Karl" wrote:
<script language="javascript">
function doOnClickBody() {
//do something
}

function doOnLoadBody() {
//do something
}
document.onclick = doOnClickBody;
window.onload =doOnLoadBody;
</script>

should work in both IE and mozilla.

Karl

"Earl Teigrob" <Ea*********@discussions.microsoft.com> wrote in message
news:13**********************************@microsof t.com...
I am trying to build a custom control to wrap my smart navigation
implimention (not microsofts 'cause it has problems)

The follow code works fine when the onclick and onload events are defined

in
the Body tag. However, when I try to set them in Javascript code, I get
errors. What am I doing wrong???
**********THIS WORKS ************
<html>
<head>
<script>
function doOnClickBody() {
document.getElementById("hdnScrollTop").value =
document.body.scrollTop;
}

function doOnLoadBody() {
document.body.scrollTop = document.getElementById("hdnScrollTop").value;
}
</script>
</head>
<body onClick="doOnClickBody();" onLoad="doOnLoadBody();">

<form id="myFromId" runat="server">
<input type="hidden" id="hdnScrollTop" runat="server" />
</form>
</body>
</html>
***********THIS DOES NOT WORK ***************

<script language="javascript">
function doOnClickBody() {
document.getElementById("<%=Me.hdnScrollTop.Client Id%>").value =
document.body.scrollTop;
}

function doOnLoadBody() {
document.body.scrollTop =
document.getElementById("<%=Me.hdnScrollTop.Client Id%>").value;
}
document.body.onclick = doOnClickBody(); //CAUSES ERROR
document.body.onload = doOnLoadBody(); //CAUSES ERROR
</script>

<body MS_POSITIONING="FlowLayout" >
<form id="Form1" method="post" runat="server">
<input type="hidden" id="hdnScrollTop" runat="server" NAME="hdnScrollTop">
</form>
</body>


Nov 18 '05 #3

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

Similar topics

6
by: Lasse | last post by:
I have done this simple function, it seems to work as intended, to solve a problem i have had for a while. I couldnt find any sample around that was working for me. I would like to test it with...
6
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...
8
by: lawrence | last post by:
I'm a beginner with Javascript and especially cross-browser Javascript. I got this working in IE, but not in Netscape 7. It seems like, in Netscape, every time I click on a button, the focus shifts...
1
by: kurt | last post by:
greetings, I'm working on a bookmarklet that needs to overwrite the current document with a frameset where the src of one of the frames is the current URL. What I've come up with works in Mozilla...
2
by: Eric Mitchell | last post by:
Hello all, I am using the document.write() method to create new content on the same page, however... I need to create a new button using this method (button in HTML). Complicating the matter...
3
by: Paul Thompson | last post by:
I am working with a special tool which pre-processes the page. Using document.write, I am composing the page while it is loading, so I need to force a reprocess of the page AFTER the page loads. ...
10
by: AC | last post by:
I had a page that does some event setup on window.onload: function prepEvents() { document.getElementById("menumap_sales").onmouseover = swapMenuSales; // etc } window.onload = prepEvents;
23
by: vunet | last post by:
It is recommended by some sources I found to create IFrames in IE using document.createElement('<iframe src="#">') instead of document.createElement('iframe'). Why and what browser versions to...
5
by: ankit1999 | last post by:
I have a problem, everytime i'm run this page http://click2travel.in/index.php i get the this error,,,
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.