473,327 Members | 2,081 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,327 software developers and data experts.

Processing HTML events in Javascript - problem

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

<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?
Jun 24 '07 #1
1 985
gits
5,390 Expert Mod 4TB
hi ...

yes thats seems to be strange ... you assign the eventhandler onclick but it seems to be interpreted as an attribute in case of doing it the way you did.

Expand|Select|Wrap|Line Numbers
  1. <body onclick="alert('ok');">
  2. <script>
  3.         var d = document.body;
  4.         alert(d.getAttribute('onclick'));
  5. </script>
  6. </body>
  7.  
when assigning a new onclick through an javascript-operation

Expand|Select|Wrap|Line Numbers
  1. d.onclick = function() { alert('test') };
  2.  
then it is treated as a property and you may ask for d.onclick ...

i think it is due to the way of setting the handler ... the first is the typical setting of an attribute for a document-node, so its treated that way ... the second is the setting of a property and so it is treated this way ...

kind regards ...
Jun 24 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Pretty woman | last post by:
Hi, I am new to web technologies, including HTML, SVG and javascript. I followed the courses for these languages on www.w3schools.com. I have a question about events raised by a SVG document....
3
by: Alexander van Meerten | last post by:
Hello, I have to make an application that works on pc and apple mac. Therefore I am investigating if it's possible to use html/javascript. The database has 10000 records and is sequentially...
4
by: Bob | last post by:
Below is sample code that illustrates what I'm trying to do. For sake of brevity I didn't include the properties of buildBtn that determine what data to request. The problem is I never see...
13
by: teddy.am | last post by:
I know this is stupid, but i've been trying to process a form while adding a function to the onClick event. as soon as i add the onClick event, the function is triggerred but the form doesn't...
5
by: Bill Henning | last post by:
Does anyone know a good method of preventing keyboard and mouse events from interrupting processing? My situation is: 1) I need to track and handle all key and mouse events 2) I need to perform...
4
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
5
by: Brian Kitt | last post by:
I have a C# application that builds dynamic HTML and renders it. Because it is rendered in this way, the input controls are not server controls. I write the entire page, which has a variable...
3
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as...
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.