42 users online (1 members and 41 guests)  


  Results 1 to 2 of 2

Related

  1. Please Help in a JavaScript Problem    Forum: Javascript Forum
    Replies: 2
  2. PHP Based Events Calendar?    Forum: PHP Forum
    Replies: 0
  3. Simple Javascript Problem - I think...    Forum: Javascript Forum
    Replies: 3
  4. Replies: 7
  5. Help me with a Javascript problem!    Forum: Javascript Forum
    Replies: 10
  1. #1
    medvegonok's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2006
    Posts
    5

    Processing HTML events in Javascript - problem

    In the following code I am trying to print out the value of document.body.onclick from javascript:

    Code:
    <BODY onclick="alert('ok')">
    
    ...
    
    <script type="text/javascript">
    alert(document.body.onclick);
    </script>
    
    ...
    </BODY>
    However, the alert in Javascript code prints out "undefined" when I open this page and not the actual value of onclick. Could somebody help me?
    Last edited by vinyl-junkie; 06-24-2007 at 12:54 PM. Reason: Added code tags

  2. #2
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Processing HTML events in Javascript - problem

    On the <body> tag you can have something like:

    Code:
    <BODY onload="alert('ok')">
    If you want a click event, you need to have a hyperlink to click on. For example:

    Code:
    <a href="mypage.htm" onclick="alert('ok')">Click Me</a>
    When doing something like this, your <script></script> code section is unnecessary.

    Hope this helps.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more