Re: Newbie Question on the Basics
- From: David Golightly <davigoli@xxxxxxxxx>
- Date: Fri, 17 Aug 2007 23:45:22 -0000
On Aug 17, 12:00 pm, Vik Rubenfeld <v...@xxxxxxxxxxxxxxxxxxxxxx>
wrote:
1) I don't see anything in the HTML that calls the JavaScript. What is
it in the HTML that calls the Javascript?
2) Autocomplete has to work by calling a function after every keypress.
What is it in the HTML that calls the Javascript after every keypress?
You're looking at an example of "unobtrusive scripting". The idea
here is that the HTML doesn't have to call the JavaScript - the JS is
perfectly capable of initializing itself. The "window.onload" sets
the window's "onload" property to a function that gets called when the
"load" event is fired, typically when the browser is done loading and
rendering the page and any dependent files (images, etc.). The
"onload" function then uses the DOM to locate nodes in the document
and, again using the DOM, attach event handlers to them, including
"onkeypress". This is a newer and not yet ubiquitous technique, and
while some feel that it's controversial (which, I suppose, makes it
controversial, no?), is generally accepted as a best practice for
making pages that degrade gracefully and allow JavaScript to provide
interaction "sugar" instead of basic functionality. Users on older
browsers or without JavaScript at all can be accomodated appropriately
when the script, not the HTML, is in control of its own
initialization. Also, larger web apps are more maintainable when JS
code is decoupled from the HTML implementation. I highly recommend
studying this code and employing See the Wikipedia article on
"Unobtrusive Javascript" for a starting point.
-David
.
- Follow-Ups:
- Re: Newbie Question on the Basics
- From: Thomas 'PointedEars' Lahn
- Re: Newbie Question on the Basics
- References:
- Newbie Question on the Basics
- From: Vik Rubenfeld
- Newbie Question on the Basics
- Prev by Date: Re: Getting and Setting key character in key event
- Next by Date: Re: Newbie Question on the Basics
- Previous by thread: Newbie Question on the Basics
- Next by thread: Re: Newbie Question on the Basics
- Index(es):
Relevant Pages
|