document.body.onclick not working in script

G

Guest

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.ClientId%>").value =
document.body.scrollTop;
}

function doOnLoadBody() {
document.body.scrollTop =
document.getElementById("<%=Me.hdnScrollTop.ClientId%>").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>
 
K

Karl

<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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top