document.body.onclick not working in script

Discussion in 'ASP .Net' started by =?Utf-8?B?RWFybCBUZWlncm9i?=, Aug 18, 2004.

  1. 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>
     
    =?Utf-8?B?RWFybCBUZWlncm9i?=, Aug 18, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?RWFybCBUZWlncm9i?=

    Karl Guest

    <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" <> wrote in message
    news:...
    > 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>
     
    Karl, Aug 19, 2004
    #2
    1. Advertising

  3. 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" <> wrote in message
    > news:...
    > > 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>

    >
    >
    >
     
    =?Utf-8?B?RWFybCBUZWlncm9i?=, Aug 23, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bob
    Replies:
    3
    Views:
    189
  2. lawrence
    Replies:
    8
    Views:
    246
    lawrence
    May 5, 2004
  3. Brian
    Replies:
    2
    Views:
    228
  4. jnag
    Replies:
    4
    Views:
    242
  5. Martin Rinehart

    document or document.body

    Martin Rinehart, Dec 6, 2008, in forum: Javascript
    Replies:
    13
    Views:
    178
    Martin Honnen
    Dec 7, 2008
Loading...

Share This Page