event handlers

J

josh

Hi, I read that professional web developer write javascript event
handler out of html tag attributes
to separate script from html structure...like css....

so when I must write an handler I should do:

i.e. document.body.onclick=foo
or document.body.addEventListener("click", foo, false);

but if I had to pass parameters????

i.e.

<script>
function foo(txt)
{
alert(txt)
}

</script>
<body onclick="foo('clicked me!!!!')"

Thanks

P.S. anonymous function doesn't seem resolve it because I can only
write arguments....Am I in error??
 
R

RobG

Hi, I read that professional web developer write javascript event
handler out of html tag attributes
to separate script from html structure...like css....

That is one strategy that can be employed, and it is a good strategy,
however there are a number of ways to achieve it if you consider both
server and client based approaches.

so when I must write an handler I should do:

i.e. document.body.onclick=foo

If you want to add a single handler, and (usually) wait for the onload
event to add it, that is one way. Or you can use a server framework
that adds the appropriate HTML attribute:

<body onclick="foo();" ... >

and have the onload handler available as soon as the body element is
(and download fewer bytes to as a bonus).

or document.body.addEventListener("click", foo, false);

And not support IE? I think you'd need a handler-adding function that
accommodates at least addEventListener and attachEvent, with fallback
to a hand-crafted method that can add multiple event handlers.

but if I had to pass parameters????

i.e.

Or do you mean e.g.?

<script>
function foo(txt)
{
alert(txt)

}

</script>
<body onclick="foo('clicked me!!!!')"

window.onload = function() {
document.body.onclick = function(){foo('click me!!!!');
}

However, as noted above, if you use a server framework that adds the
handler in the HTML, you actually maintain the separation of script
and HTML at the server where it counts for you, download less code and
your visitors aren't waiting for the onload event to add your handler.

P.S. anonymous function doesn't seem resolve it because I can only
write arguments....Am I in error??

I don't know what you mean by "I can only write arguments".
 
T

Thomas 'PointedEars' Lahn

josh said:
Hi, I read that professional web developer write javascript event
handler out of html tag attributes to separate script from html structure

Since DOM stripting is inherently attached to the markup it operates on,
either you have read utter nonsense or you have completely misunderstood
what was written. If the former and it was a book, rip it apart, shredder
it, throw it in the trash can, burn it, and sue the author for being
incompetent.
..like css....

CSS is a formatting language (not a programming language) which is attached
to its markup with one or more of element relation, `id', `class' or `style'
attribute.
so when I must write an handler I should do:

i.e. document.body.onclick=foo
or document.body.addEventListener("click", foo, false);

.... or document.body.attachEvent("onclick", ...) (MSHTML) or whatever
proprietary means the UA's DOM supports.

And you would have to test for each of it, with a remaining margin of error
since not all DOM features can be tested for exactly. Whereas with an
entirely standards compliant event handler attribute you would not have to.

Now which approach would the professional Web developer prefer?
but if I had to pass parameters????

Your Question Mark key is borken. But if you had to pass parameters, you
would use a function expression:

document.body.addEventListener("click", function() { foo(bar); }, false);
i.e.

<script>
http://validator.w3.org/

function foo(txt)
{
alert(txt)
}

</script>
<body onclick="foo('clicked me!!!!')"

That is the way, with only one exclamation mark of course.
[...]
P.S. anonymous function doesn't seem resolve it because I can only
write arguments....Am I in error??

Parse error.


PointedEars
 
T

Thomas 'PointedEars' Lahn

josh said:
Oh, yes I used that keyword improperly. I wanted to say:
e.g.
document.body.onclick = function(arg1)
{
// ...
}
but in that code formal parameter arg1 is not usable because I can't
pass any actual parameter

Event listeners have a fixed signature that is defined by the UA's DOM.
See my other followup.


PointedEars
 
S

Stevo

Thomas said:
either you have read utter nonsense or you have completely misunderstood
what was written. If the former and it was a book, rip it apart, shredder
it, throw it in the trash can, burn it, and sue the author for being
incompetent.

Now which approach would the professional Web developer prefer?


Your Question Mark key is borken.

Did anyone ever tell you that your messages come across as being very
nasty. I wonder if you're that evil to people you work with that ask you
questions face to face, or if it's just here where you don't have to
face the people you attack. Don't bother replying to me, I'm killing
this thread so Thunderbird doesn't show it to me anymore. I don't want
to see what kind of response you'll give to me. I already imagine it
will be savage so I don't need to see it.

You need to remember one thing when you're answering a question here. If
they knew as much as you do, they wouldn't come asking questions. Not
everyone has your skill level in Javascript or the myriad of web
technology that's available. People get thrown in the deep end sometimes
by their boss, or they're a kid that wants to teach themself, or maybe
they just inherited a support task. You might say to them well go learn
it then, and that's just what they're doing. No javascript book explains
every type of programming task you'll encounter, so when a newbie has
questions that the book (or google) don't provide an answer to, then
this is one of the places they'll find their way to. Calling them stupid
and shouting the rules of a group they've never visited is just plain
nasty, and you're the worst offender of this.
 
J

josh

Since DOM stripting is inherently attached to the markup it operates on,
either you have read utter nonsense or you have completely misunderstood
what was written. If the former and it was a book, rip it apart, shredder
it, throw it in the trash can, burn it, and sue the author for being
incompetent.

I quote the exact phrase taken by JavaScript Bible Sixth Ed and I
think that
this is a great book and the author Danny is also a professional
javascript programmer!
"""" Separating content from scripting
Those who use CSS to style their sites have learned that separating
style definitions from the HTML markup
makes a huge improvement in productivity when it comes time to change
colors or font specifications
throughout a site. Instead of having to modify hundreds of <font> tag
specifications scattered around the
site, all it takes is a simple tweak of a single CSS rule in one .css
file to have that change be implemented
immediately across the board.
The notion of using HTML purely for a page's structure has also
impacted scripting. It is rare these days for
a professional scripter to put an event handler attribute inside an
HTML tag. That would be considered too
much mixing of content with behavior. In other words, the HTML markup
should be able to stand on its
own so that those with nonscriptable browsers (including those with
vision or motor disabilities who use
specialized browsers) can still get the fundamental information
provided by the page. Any scripting that
impacts the display or behavior of the page is added to the page after
the HTML markup has loaded and
rendered. Even assigning events to elements is done by script after
the page load.
Script code is more commonly linked into a page from an external .js
file. This isn't part of the separation
of content and scripts trend, but a practice that offers many
benefits, such as the same code being instantly
usable on multiple pages. Additionally, when projects involve many
code chefs, scripters can work on their
code while writers work on the HTML and designers work on their
external CSS code """""

However that is only an opinion ... and I'm agree with him (may be you
not)
CSS is a formatting language (not a programming language) which is attached
to its markup with one or more of element relation, `id', `class' or `style'
attribute.

in fact also CSS is attached to HTML (like javascript object code to
tags) and
today web developer doesn't "mix" presentation code (css) with
structural code (html)...
you are contradicting yourself.....
document.body.addEventListener("click", function() { foo(bar); }, false);

thanks this is the answer I was searching.....

Josh
 
T

Thomas 'PointedEars' Lahn

josh said:
I quote the exact phrase taken by JavaScript Bible Sixth Ed and I
think that this is a great book and the author Danny is also a professional
javascript programmer!

You are wrong. The book you are referring to is merely considered by some
to be the best of the bad JavaScript books known around here.

I for one have seen too many very bad examples out of it being posted here
to refrain from ever buying it and to recommend against buying it.
Partially because it is hopelessly outdated, partially because it is
factually wrong. YMMV, but then please don't complain here if it does not
work as expected. You have been warned.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
You are wrong. The book you are referring to is merely considered by some
to be the best of the bad JavaScript books known around here.

Sorry, that was Flanagan's book. The book you are referring to is much
worse than that. Google is your friend. [psf 6.1]


PointedEars
 
J

josh

Thomas said:
josh said:
[...] Thomas 'PointedEars' Lahn [...] wrote:
Since DOM stripting is inherently attached to the markup it operates on,
either you have read utter nonsense or you have completely misunderstood
what was written. If the former and it was a book, rip it apart, shredder
it, throw it in the trash can, burn it, and sue the author for being
incompetent.
I quote the exact phrase taken by JavaScript Bible Sixth Ed and I
think that this is a great book and the author Danny is also a professional
javascript programmer!
You are wrong. The book you are referring to is merely considered by some
to be the best of the bad JavaScript books known around here.

Sorry, that was Flanagan's book. The book you are referring to is much
worse than that. Google is your friend. [psf 6.1]

PointedEars

Really? Please link me where is written and who wrote review! I don't
seem so!
and which are for you best javascript books? or the books where did
you study?
I'm very curious!
 
T

Tim Streater

Thomas 'PointedEars' Lahn said:
Thomas said:
josh said:
[...] Thomas 'PointedEars' Lahn [...] wrote:
Since DOM stripting is inherently attached to the markup it operates on,
either you have read utter nonsense or you have completely misunderstood
what was written. If the former and it was a book, rip it apart, shredder
it, throw it in the trash can, burn it, and sue the author for being
incompetent.
I quote the exact phrase taken by JavaScript Bible Sixth Ed and I
think that this is a great book and the author Danny is also a professional
javascript programmer!

You are wrong. The book you are referring to is merely considered by some
to be the best of the bad JavaScript books known around here.

Sorry, that was Flanagan's book. The book you are referring to is much
worse than that. Google is your friend. [psf 6.1]

More use would be names of some books you consider good, and why.
Otherwise this is just a guessing game.
 
T

Thomas 'PointedEars' Lahn

Tim said:
Thomas said:
josh wrote:
I quote the exact phrase taken by JavaScript Bible Sixth Ed and I
think that this is a great book and the author Danny is also a professional
javascript programmer!
You are wrong. The book you are referring to is merely considered by some
to be the best of the bad JavaScript books known around here.
Sorry, that was Flanagan's book. The book you are referring to is much
worse than that. Google is your friend. [psf 6.1]

More use would be names of some books you consider good, and why.

There is not any, because I never had the need to (buy and) read one about
this topic. Online resources, including this group, sufficed to date.
Why that is so, can be read in <[email protected]>,
by Richard Cornford:

| Probably we all started off learning javascript from books. As you learn
| more, and try more, one of the things you learn is how bad those books
| were. At this point nobody is going to start looking at tutorial books
| that attempt to round up the techniques we have been using for years,
| without being paid to do so. And that is assuming such books exist.
|
| That leaves you with a problem; the people reading such books are doing
| so precisely because they don't know enough to judge them in the wider
| context, and the people who could make the judgment are not motivated to
| even look at those books.


HTH

PointedEars
 
J

josh

josh said the following on 8/14/2007 8:10 AM:



Danny Goodman is an author, not a programmer.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

oh so who does write a programming book is only an author?
please explain me this difference! it's a new concept for me...
 
T

Thomas 'PointedEars' Lahn

josh said:
josh said the following on 8/14/2007 8:10 AM:
On 14 Ago, 13:48, Thomas 'PointedEars' Lahn <[email protected]>
wrote:
Since DOM stripting is inherently attached to the markup it operates on,
either you have read utter nonsense or you have completely misunderstood
what was written. If the former and it was a book, rip it apart, shredder
it, throw it in the trash can, burn it, and sue the author for being
incompetent.
I quote the exact phrase taken by JavaScript Bible Sixth Ed and I
think that this is a great book and the author Danny is also a
professional javascript programmer!
Danny Goodman is an author, not a programmer.
[...]

oh so who does write a programming book is only an author?

Because common programming sense had no part in writing it.
please explain me this difference! it's a new concept for me...

E.g. because of this from one of his articles from View Source in 1999 [1]:

| A DEBUGGING LIBRARY COMPONENT
| [...]
| Listing 1
|
| // Simple browser sniffing needed here
| var isNav = (navigator.appName == "Netscape")
| // Output list of properties for the object
| function dumpProps(objName) {
| [...]
| for (var i in obj) {
| if (i != "outerHTML" && i != "outerText" && i != "innerHTML"
| && i != "innerText" && i != "domain") {
| msg += objName + "." + i + "=" + obj + "\n"
| if (count > maxProps) {
| // Output a batch
| if (isNav) {
| java.lang.System.out.println(msg)
| }
| else {
| alert(msg)
| }
| [...]

Having seen this at that time, I daresay, show me a snippet of Goodman's
script code and I tell you why NOT to use it.

Please trim your quotes.


PointedEars
___________
[1]
http://web.archive.org/web/20040803...html?content=goodman_debug/goodman_debug.html
 
T

The Natural Philosopher

josh said:
oh so who does write a programming book is only an author?
please explain me this difference! it's a new concept for me...
An autohr writes books, a programmer writes code.

There, even a Mac users should be able to grasp the basic difference.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>, Tue,
14 Aug 2007 15:41:17 said:
Thomas 'PointedEars' Lahn wrote:
You are wrong. The book you are referring to is merely considered by some
to be the best of the bad JavaScript books known around here.

Sorry, that was Flanagan's book. The book you are referring to is much
worse than that. Google is your friend. [psf 6.1]

Your ill-tempered nature makes you post too hastily and too carelessly.
Are you still trying to grow up or is it a peculiar form of senility
that you have?
 
J

josh

An autohr writes books, a programmer writes code.

ok stop with humor!
Simply I think that if someone write a programming book or a
techinical book
can't be only an author. May be if someone is a programmer could not
be able
to write a programming book. In fact is not simple to write technical
concept...
Sure if someone write only books and make few complex programs will
not be ever a great
programmer but this is another story!
There, even a Mac users should be able to grasp the basic difference.
I wonder but here in this newsgoup is not possible to make post or to
say
opinions without being insulted?
I think that also Mac users are able to manage computer or do you
think that it's only
a Linux users prerogative?
P.S.
I use GNU/Linux!
 
L

Laurent vilday

josh a écrit :
Thomas said:
You are wrong. The book you are referring to is merely considered by some
to be the best of the bad JavaScript books known around here.
Sorry, that was Flanagan's book. The book you are referring to is much
worse than that. Google is your friend. [psf 6.1]

which are for you best javascript books? or the books where did
you study?

LOL. no, not LOL ... ROFLMAO :)

Thomas doesn't need any books to study, he just know.
 
T

Thomas 'PointedEars' Lahn

Laurent said:
josh a écrit :
Thomas 'PointedEars' Lahn wrote:
You are wrong. The book you are referring to is merely considered by some
to be the best of the bad JavaScript books known around here.
Sorry, that was Flanagan's book. The book you are referring to is much
worse than that. Google is your friend. [psf 6.1]
which are for you best javascript books? or the books where did
you study?

LOL. no, not LOL ... ROFLMAO :)

Please return to your chat channel.
Thomas doesn't need any books to study,

I did not need to, that is correct.
he just know.

Analphabetism seems to be a common disease on Usenet nowadays.

<[email protected]>


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top