By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,695 Members | 1,638 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,695 IT Pros & Developers. It's quick & easy.

FOR...EVENT

P: n/a
I read the book JavaScript the Definitive Guide, 3rd edition. On P217
it says I can use FOR...EVENT in <script> tag. I tried this code, it
does not display the alert() window in IE 6.0. Can you tell me why?
Thanks.

<HTML><HEAD></HEAD>
<BODY>
<FORM NAME="from1">
<INPUT TYPE="Button" NAME="cmdClickMe" VALUE="Click Me">
<SCRIPT FOR="cmdClickMe" EVENT="onClick">
alert("Hello!")
</SCRIPT></FORM>
</BODY> </HTML>

Aug 18 '05 #1
Share this Question
Share on Google+
17 Replies


P: n/a
have you tried

<INPUT TYPE="Button" NAME="cmdClickMe" VALUE="Click Me"
onclick=alert("Hello!")>
?

Aug 18 '05 #2

P: n/a
Yes. It displays the msg box.

Aug 18 '05 #3

P: n/a
steve wrote:
I read the book JavaScript the Definitive Guide, 3rd edition. On P217
it says I can use FOR...EVENT in <script> tag.
If its talking about HTML, its wrong.

<!ELEMENT SCRIPT - - %Script; -- script statements -->
<!ATTLIST SCRIPT
charset %Charset; #IMPLIED -- char encoding of linked resource --
type %ContentType; #REQUIRED -- content type of script language --
src %URI; #IMPLIED -- URI for an external script --
defer (defer) #IMPLIED -- UA may defer execution of script --


http://www.w3.org/TR/html4/interact/...ml#edef-SCRIPT

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Aug 18 '05 #4

P: n/a
steve wrote:
I read the book JavaScript the Definitive Guide, 3rd edition. On P217
it says I can use FOR...EVENT in <script> tag. I tried this code, it
does not display the alert() window in IE 6.0. Can you tell me why?
Thanks.

<HTML><HEAD></HEAD>
<BODY>
<FORM NAME="from1">
<INPUT TYPE="Button" NAME="cmdClickMe" VALUE="Click Me">
<SCRIPT FOR="cmdClickMe" EVENT="onClick">
alert("Hello!")
</SCRIPT></FORM>
</BODY> </HTML>


I found this on msdn:

http://msdn.microsoft.com/workshop/a...ties/event.asp

It seems to work, even in IE 7b. It doesn't work in Firefox though.

Kevin N.
Aug 18 '05 #5

P: n/a
Kevin Newman wrote:
steve wrote:
I read the book JavaScript the Definitive Guide, 3rd edition. On P217
it says I can use FOR...EVENT in <script> tag. I tried this code, it
does not display the alert() window in IE 6.0. Can you tell me why?
Thanks.

<HTML><HEAD></HEAD>
<BODY>
<FORM NAME="from1">
<INPUT TYPE="Button" NAME="cmdClickMe" VALUE="Click Me">
<SCRIPT FOR="cmdClickMe" EVENT="onClick">
alert("Hello!")
</SCRIPT></FORM>
</BODY> </HTML>


I found this on msdn:

http://msdn.microsoft.com/workshop/a...ties/event.asp
It seems to work, even in IE 7b. It doesn't work in Firefox though.

Kevin N.


I see it, you have to put the parenthesis in there (event="onClick()")
Aug 18 '05 #6

P: n/a
Kevin Newman wrote:
Kevin Newman wrote:

[snip]


I found this on msdn:

http://msdn.microsoft.com/workshop/a...ties/event.asp
It seems to work, even in IE 7b. It doesn't work in Firefox though.

Kevin N.

I see it, you have to put the parenthesis in there (event="onClick()")

I found this on msdn:
"This feature requires Microsoft® Internet Explorer 4.0 or later."
(Windows only, too)
Mick
Aug 18 '05 #7

P: n/a
After I changed it to onclick, it works. But I am confused. If it is
javascript, it should be onClick.

Aug 19 '05 #8

P: n/a
steve wrote:
After I changed it to onclick, it works. But I am confused. If it is
javascript, it should be onClick.


http://www.w3.org/TR/html4/interact/scripts.html#events

--
Gus
Aug 19 '05 #9

P: n/a
Thank. So it is the HTML. But HTML is not case sensitive. Why does
onClick not work?

Aug 19 '05 #10

P: n/a
steve wrote:

Please learn to quote.
http://www.cse.ohio-state.edu/cgi-bin/rfc/rfc1855.html - Page 7, 7th bullet
point (not counting the second half of one from the previous page).
Thank. So it is the HTML. But HTML is not case sensitive. Why does
onClick not work?


HTML element and attribute names are case insensitive. The *content* of this
non-standard, non-HTML, non-"sane to use on the WWW" attribute isn't.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Aug 19 '05 #11

P: n/a
steve wrote:
I read the book JavaScript the Definitive Guide, 3rd edition. On P217
it says I can use FOR...EVENT in <script> tag. I tried this code, it
does not display the alert() window in IE 6.0. Can you tell me why?
Thanks.

<HTML><HEAD></HEAD>
<BODY>
<FORM NAME="from1">
<INPUT TYPE="Button" NAME="cmdClickMe" VALUE="Click Me">
<SCRIPT FOR="cmdClickMe" EVENT="onClick">
alert("Hello!")
</SCRIPT></FORM>
</BODY> </HTML>


When you don't want to include any javascript in your HTML tag, which
sometimes is very desirable, you can use the addEventListener for decent
browsers such as firefox, and attachEvent for Internet Explorer (4+ ?).

<input type="button" id="cmdClickMe" name="cmdClickMe" value="Click Me">
<script type="text/javascript">
function hello(event) {
alert("Hello!")
}
var btn = document.getElementById("cmdClickMe");
if (isInternetExplorer())
btn.attachEvent("onclick", hello);
else
btn.addEventListener("click", hello, false);
</script>
Aug 19 '05 #12

P: n/a
VK
>> Thank. So it is the HTML. But HTML is not case sensitive. Why does
onClick not work?

HTML element and attribute names are case insensitive.
The *content* of this non-standard, non-HTML,
non-"sane to use on the WWW" attribute isn't.


Event model is not a part of HTML. They are part of the used scripting
language (JavaScript, JScript, VBScript). So *formally* event names
should be case-sensitive in case of JavaScript/JScript.

Event names for *intrinsic event handlers* are case-insensitive for
legacy issues, because they were introduced as such since Netscape 2
(when no one gave a damn about W3). They will remain such for another
decade at least I promise.
So within <body> and other HTML elements you can use "onClick" or
"onclick" or "onCLICK" etc. (it doesn't mean you should do it).

Within the script they are case-sensitive as they should and must be
all *in lower case*:
window.onload, element.onclick etc.

Within the script event listener declarations attachEvent (IE) and
addEventListener (FF) they must be also all *in lower case*. Moreover
in such case IE requires "on forms": onload, onclick; FF requires "pure
forms": load, click.

The books don't tell too much about this mess for two reasons:
1) Traditionally they are written by contracted amateurs who barely
know themselves that the hey they are writing about (just produce
enough sheets for payroll).
2) The info like this breaks the picture of the Kingdom of Standards
with W3 as the acting king.

Aug 19 '05 #13

P: n/a
VK wrote:
The books don't tell too much about this mess for two reasons:
1) Traditionally they are written by contracted amateurs who barely
know themselves that the hey they are writing about (just produce
enough sheets for payroll).
2) The info like this breaks the picture of the Kingdom of Standards
with W3 as the acting king.


Often true.
However I read "JavaScript Second Edition - The Complete Reference" and
was quite frank about the mess between all of this, and tried its best
to describe all the different object models.

I would recommend this book to anyone who is searching for a good book
about Javascript.
Aug 19 '05 #14

P: n/a
VK wrote:
Thank. So it is the HTML. But HTML is not case sensitive. Why does
onClick not work?
HTML element and attribute names are case insensitive.
The *content* of this non-standard, non-HTML,
non-"sane to use on the WWW" attribute isn't.


Event model is not a part of HTML. They are part of the used scripting
language (JavaScript, JScript, VBScript).


Event models are not part of the scripting language, they are
implemented by the browser developer and may conform to the W3C model in
whole, part or not at all.
So *formally* event names
should be case-sensitive in case of JavaScript/JScript.
Event names are defined in the HTML standard and as they are element
attributes, they are not case sensitive. Put them into XHTML, where
element attributes are case sensitive, and they are.

Event names for *intrinsic event handlers* are case-insensitive for
legacy issues,
They are case insensitive in HTML because HTML attributes are defined as
being case insensitive. That's the end of it. The legacy is that of
HTML, which was around long before Netscape or IE.
because they were introduced as such since Netscape 2
(when no one gave a damn about W3). They will remain such for another
decade at least I promise.
Tim Berners-Lee wrote the first version of HTML in 1989. In October 1994
he founded the W3C; Netscape 2.0 was released in March 1996 and claimed
support for HTML 2 and some of HTML 3. The W3C released the HTML 3.2
reference specification in January 1997, HTML 4.0 was released in
December 1997.

I think the Netscape guys certainly did give a damn, and so did Microsoft.

Netscape introduced intrinsic event names as case insensitive, which was
in conformance with the HTML specification. How does that indicate that
Netscape didn't care about the W3C? Or Microsoft?

Microsoft invented the for..event script element and *chose* to make the
attributes case sensitive. You would have to ask them why they chose to
not implement them in accordance with the HTML specification.

You may note that all other script element attributes are case
insensitive in HTML. Attribute values may or may not be, that is beyond
the scope of the specification.
So within <body> and other HTML elements you can use "onClick" or
"onclick" or "onCLICK" etc. (it doesn't mean you should do it).

Within the script they are case-sensitive as they should and must be
all *in lower case*:
window.onload, element.onclick etc.


ECMAScript happens to be case sensitive, so the script side of the API
between the DOM and ECMAScript is also case sensitive. I presume if you
chose to write an API for a non-case sensitive script language then
attribute names within the script would not be case sensitive.

[...]

--
Rob
Aug 19 '05 #15

P: n/a
On Sat, 20 Aug 2005 00:13:50 +1000, RobG <rg***@iinet.net.au> wrote:
Microsoft invented the for..event script element and *chose* to make the
attributes case sensitive. You would have to ask them why they chose to
not implement them in accordance with the HTML specification.

You may note that all other script element attributes are case
insensitive in HTML. Attribute values may or may not be, that is beyond
the scope of the specification.


The -for- and -event- attributes on the -script- element are not
case-sensitive, their values are.

<span id="myId">TEST</span>
<script Type="text/javascript" For="myId" Event="onclick">
alert('this alerts');
</script>

<span id="myId">TEST</span>
<script Type="text/javascript" For="myId" Event="onClick">
alert('this does not alert');
</script>

It seems to me that the value of the -event- attribute of the -script-
tag is entirely consistent with other aspects of JScript. In other
words:

<span id="myId">TEST</span>
<script Type="text/javascript" For="myId" Event="onclick">
alert('hi');
</script>

and

<span id="myId">TEST</span>
<script type="text/javascript">
myId.attachEvent('onclick', function() { alert('hi'); });
</script>

and

<span id="myId">TEST</span>
<script type="text/javascript">
myId.onclick= function() { alert('hi'); };
</script>

provide almost (but not entirely) the same functionality. One
signifcant difference would be that in the first example, the binding
of the event to the element happens (I am going to assume) during
parsing, while in the other two cases, the binding does not happen
until the script runs. Anyway, the point is, the case-sensitivity of
the value (not name) of the -event- attribute of the -script- tag
(regardless of what you think of the syntax or functionality) is
consistent with other aspects of the language.

--
Grant Wagner <sq*******@yahoo.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Aug 19 '05 #16

P: n/a
Grant Wagner wrote:
On Sat, 20 Aug 2005 00:13:50 +1000, RobG <rg***@iinet.net.au> wrote:

Microsoft invented the for..event script element and *chose* to make the
attributes case sensitive. You would have to ask them why they chose to
not implement them in accordance with the HTML specification.

You may note that all other script element attributes are case
insensitive in HTML. Attribute values may or may not be, that is beyond
the scope of the specification.

The -for- and -event- attributes on the -script- element are not
case-sensitive, their values are.


Ah, my bad. I got confused by VK's comment regarding tag attributes
attribute values... :-x

[...]

--
Rob
Aug 19 '05 #17

P: n/a
VK
Grant Wagner wrote:
<CODE>
<span id="myId">TEST</span>
<script Type="text/javascript" For="myId" Event="onclick">
alert('this alerts');
</script>
</CODE>
Did you try:
<script Type="text/javascript" For="myId" Event="onclick()">
?
It works too. So you can use both onevent and onevent() forms.
So much for consistency :-) But yes, it is case-sensitive and it wants
event names on'ed and in lower-case.
the binding of the event to the element happens (I am going to assume)
during parsing, while in the other two cases, the binding does not happen
until the script runs.


Well (I am going to assume) that the binding will not occure until the
relevant object is "ready to interact with" (included in the internal
DOM scheme).
<script for="something" event="onevent()"> frees you from putting all
event attachments into some onload function. That would be the only
plus if you don't care about other browsers besides IE.

Actually I'm doing a IE-centered contract job right now, so I'm
sniffing the darkest ("proprietariest") corners of MSDN I never was
before. It gets to me that SCRIPT-FOR-EVENT and attachEvent() are
really not what people are trying to use them for. They are again (like
XMLHTTP) parts of a bigger picture. In this case the WebService and
other behaviors are in the centre. So yes, you can use SCRIPT-FOR-EVENT
to attach events to the page elements and you can use attachEvent as an
analog of addEventListener, but these are just side effects of their
behavior/remote service oriented nature.
IMHO.

Aug 19 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.