473,503 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The mothod "on" not available for a button?!

It's perhaps something elementary. I tried
to do suff as follows.

document.getElementById ('Button1').on (
'click', funcion () {});

For some reason, the method isn't there. According
to FireBug i get this.

document.getElementById ('Button1').on
(gives nothing - no such method)

while

Ext.get ('Button1').on
(gives function ())

What do i miss?

--
Regards
Konrad Viltersten
Jun 27 '08 #1
6 1198
On 23 Mai, 12:08, "K Viltersten" <t...@viltersten.comwrote:
It's perhaps something elementary. I tried
to do suff as follows.

document.getElementById ('Button1').on (
'click', funcion () {});

For some reason, the method isn't there. According
to FireBug i get this.
Because there isn't such a method.
document.getElementById ('Button1').on
(gives nothing - no such method)
Right. document.getElementById returns a DOM reference, and the DOM
API doesn't have a method "on".
Ext.get ('Button1').on
(gives function ())
Ext.get is a method of a 3rd party libary (I'm guessing "Ext" :-) that
returns something else than a DOM reference which does have an "on"
method.

I'd suggest as a JavaScript beginner, you should avoid using 3rd party
libraries until you know what you're doing, or at least read their
documentation.

With the DOM API events are set either directly:

document.getElementById('Button1').onclick = function() { ... }

or with addEventListener:

document.getElementById('Button1').addEventListene r("click",
function() { ... }, true);

Which IE however doesn't support. You need to use attachEvent for IE.
More details at: http://developer.mozilla.org/en/docs...dEventListener

Robin
Jun 27 '08 #2
On May 23, 11:08 am, K Viltersten wrote:
It's perhaps something elementary. I tried
to do suff as follows.

document.getElementById ('Button1').on (
'click', funcion () {});

For some reason, the method isn't there. According
to FireBug i get this.

document.getElementById ('Button1').on
(gives nothing - no such method)

while

Ext.get ('Button1').on
(gives function ())

What do i miss?
That - document.getElementById - returns an element from the DOM and -
Ext.get -(whatever that is) either returns a different sort of object
or returns a DOM element that has been subject to (direct or indirect)
augmentation prior to being returned.

Neither the W3C DOM specifications nor historical practice suggest
that an element should be expected to have an - on - method.
Jun 27 '08 #3
Robin Rattay wrote:
With the DOM API events are set either directly:

document.getElementById('Button1').onclick = function() { ... }

or with addEventListener:

document.getElementById('Button1').addEventListene r("click",
function() { ... }, true);
Reference Worms[tm] are error-prone, and should therefore be avoided.

// add feature tests here

var o = document.getElementById('Button1');
if (o)
{
// add feature tests here

o.addEventListener("click", function() { ... }, true)
}

Adding a capturing event listener (`true') through the standards-compliant
addEventListener() method of the EventTarget interface is _not_ equivalent
to assigning to the proprietary event handler property (`on...').
Therefore, the third argument should be `false' unless compatibility with
non-DOM2 UAs is not an issue (seldom).
Which IE however doesn't support. You need to use attachEvent for IE.
However, IE/MSHTML does support the proprietary event handler property,
which should to be used instead of attachEvent():

http://www.quirksmode.org/blog/archi...nt_consid.html
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jun 27 '08 #4
>It's perhaps something elementary. I tried
>to do suff as follows.

document.getElementById ('Button1').on (
'click', funcion () {});

For some reason, the method isn't there. According
to FireBug i get this.

Because there isn't such a method.
>document.getElementById ('Button1').on
(gives nothing - no such method)

Right. document.getElementById returns a DOM reference, and the DOM
API doesn't have a method "on".
>Ext.get ('Button1').on
(gives function ())

Ext.get is a method of a 3rd party libary (I'm guessing "Ext" :-) that
returns something else than a DOM reference which does have an "on"
method.

I'd suggest as a JavaScript beginner, you should avoid using 3rd party
libraries until you know what you're doing, or at least read their
documentation.

With the DOM API events are set either directly:

document.getElementById('Button1').onclick = function() { ... }

or with addEventListener:

document.getElementById('Button1').addEventListene r("click",
function() { ... }, true);

Which IE however doesn't support. You need to use attachEvent for IE.
More details at:
http://developer.mozilla.org/en/docs...dEventListener
Thanks for the head up regarding IE. Also, thanks for the
very insightful reply.

--
Regards
Konrad Viltersten
Jun 27 '08 #5
Henry wrote:
On May 23, 11:08 am, K Viltersten wrote:
>document.getElementById ('Button1').on
(gives nothing - no such method)

while

Ext.get ('Button1').on
(gives function ())

What do i miss?

That - document.getElementById - returns an element from the DOM and -
Ext.get -(whatever that is) either returns a different sort of object
or returns a DOM element that has been subject to (direct or indirect)
augmentation prior to being returned.
And it should also be noted again that direct augmentation is inherently
error-prone as host objects may implement their own internal [[Put]]
algorithm allowed per the ECMAScript Specification. And so it can be
observed that often code written by clueless/inexperienced people directly
augments host objects, they not being aware that their code may break any
minute.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jun 27 '08 #6
Thomas 'PointedEars' Lahn wrote:
>document.getElementById('Button1').addEventListen er("click",

Reference Worms[tm] are error-prone, and should therefore be avoided.

PointedEars
Reference worms. I like it. Did you make that up ? I've always wanted a
term to describe what that code above is doing (incorrectly assuming
that Button1 will be returned as an object and disregarding the
possibility that it might return null / undefined).
Jun 27 '08 #7

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

Similar topics

8
12364
by: The CQMMAN | last post by:
Hello, When I try to connect to my Oracle instance on the W2K server that it is installed on, using SQLPLUS (ie, SQLPLUS user/password@instance), I get: ORA-01034: ORACLE not available...
5
8468
by: Quinn | last post by:
When users clicked a unkown mime type link such as Zip on my website, a "Save/Open/Cancel" dialog box pops up. Is there a way to detect which button users clicked by using ASP? actually I only what...
5
2403
by: Dani | last post by:
Hello everybody, I have some code that disables form elements on body load, but I notice when I hit the "back" button, I need to re-enable the form elements (that is done by clicking on a radial...
0
888
by: David P. Donahue | last post by:
I have a C# website where some of the pages contain various inputs and buttons. For example, a FAQ page would have an input for the question and a button to submit the question... However, if the...
3
3708
by: Ahmed Ayoub | last post by:
i forgot how to create Textboxes & Label Dynamically. Meaning, i want to make them .. initialize their position .. and view them and interact with them.
2
4833
by: Serious_Practitioner | last post by:
Good day, and thank you in advance for any assistance. I'm having trouble with something that I'm trying for the first time. Using Access 2000 - I want to run a function either on the click of a...
1
4668
by: ranabhavin2 | last post by:
Hi, on button click I want to open new window each time. Currently when I m click on button second time then my new window is replaced with my original window. We can do it in hyperlink by ...
0
883
by: Tequilaman | last post by:
Has anybody here every created a program to insert data from a csv into a webform, including a click to a 'go on' button and choosing in dropdowns according to the information in the csv? I'm...
3
4441
Curtis Rutland
by: Curtis Rutland | last post by:
OK, I have a question. I have a problem. I'm trying to catch all KeyDown events on a button, but the problem is when I press the "Enter" key, the button's "Click" event is triggered, not the...
0
7201
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
7083
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
7278
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,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6988
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
5011
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
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
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...
1
734
muto222
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.