473,473 Members | 4,189 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

onclick

Any idea why this simple alert does not work? took this straight out of
someone elses answer to my last question ...
<html>

<head>
<title>Test</title>
<style type="text/css">
#push {
position:absolute;
background:#000;
top:50px;
width: 100px;
height: 100px;
left:100px;"
</style>
</head>

<body>

<div id="push" onclick="new Function('alert(this);')">
&nbsp;
</div>

</body>

</html>

Nov 14 '06 #1
2 1317
eddie wrote:
Any idea why this simple alert does not work?
<div id="push" onclick="new Function('alert(this);')">
A simple alert would be
<div id="push" onclick="alert(this);">

What you have simply creates a new function with the Function
constructor. The body of the function has an alert call but the function
is nowhere called.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 14 '06 #2
eddie wrote:
Any idea why this simple alert does not work?
It does 'work', it just doesn't do what you want it to do. But as you
are not letting on what that is you will get no closer to doing it
here.
took this straight
out of someone elses answer to my last question ...
So this had an author who you could have replied to in order to get an
answer directly?

<snip>
<div id="push" onclick="new Function('alert(this);')">
<snip>

The string value of an intrinsic event attribute in HTML is used by the
browser to create a function object (as the body source code for the
function). The function object is then assigned to a property of the
DOM element that corresponds with the element in which the attribute
was declared, and executed as a method of that element when the
pertinent event happens.

This process applied to your mark-up above is approximately equivalent
of scripting:-

referenceToDivElement.onlclick = function(event){
new Function('alert(this);');
};

- that is, the onclick handler assigned to the DIV element acts by
creating a new function object and then doing nothing with that object.
Any browser you test this with almost certainly is working exactly as
programmed, but the process programmed has no visible manifestation.

Richard.

Nov 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Shock | last post by:
Hello everyone, I am having a problem with the program below. I have isolated the problem to the onclick event that is located throughout arrQuestions. The onclick event refers to a function...
17
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
2
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display...
3
by: Jamie Jackson | last post by:
I'm rewriting all links' onclick events, but I'm having a problem. The onclick event that I'm inserting works correctly in Opera, but not in FF or IE. I'm retroactively adding the statement...
7
by: extremerep | last post by:
My task is to change the value of a button and then make it functional with the onClick handler. Changing the value to "Play Again" works, but making the onClick work accordingly does not. The...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.