Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > document.body.onclick not working in script

Reply
Thread Tools

document.body.onclick not working in script

 
 
=?Utf-8?B?RWFybCBUZWlncm9i?=
Guest
Posts: n/a
 
      08-18-2004
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>
 
Reply With Quote
 
 
 
 
Karl
Guest
Posts: n/a
 
      08-18-2004
<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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?RWFybCBUZWlncm9i?=
Guest
Posts: n/a
 
      08-23-2004
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute a script from another script and other script does notdo busy wait. Rajat Python 3 01-08-2010 02:05 PM
RE: How to execute a script from another script and other script doesnotdo busy wait. VYAS ASHISH M-NTB837 Python 2 01-07-2010 08:18 PM
Webresource script not embedded? not working. zb ASP .Net 2 11-07-2007 01:40 AM
wifi not working on new hp, or not working after live update =?Utf-8?B?RHJhZ29ueA==?= Wireless Networking 1 10-01-2005 11:17 PM
Script is working in IE, but not working in Netscape 7 - trouble with document.selection.createRange(); lawrence Javascript 8 05-05-2004 01:43 AM



Advertisments