Re: Newbie Question on the Basics



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

.



Relevant Pages

  • Re: JS, DOM and tr... IE problems!
    ... I've got a problem with javascript and DOM. ... Capitalisation is often used in HTML markup, ... If you post what your browser is actually getting (e.g. using view ...
    (comp.lang.javascript)
  • Re: Why doesnt IE show full html source?
    ... if you use smart navigation, javascript changes the dom on the fly, so the ... in turn is generated by javascript - for which you can see the source). ... need to use a dom inspector to see the changes made by smart nav. ... | Why does IE not show the full html source when I try to view the source?? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Intrepreting Javascript within C#
    ... Right, and using MSHTML, you would load the page, and then your bot ... DOM to get whatever elements were changed to have the new URL. ... If this is in the context of an HTML page, then why not use an HTML ... document host like MSHTML to execute the javascript? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: The Problems of TeX
    ... errors and makes very heavy use of javascript that I can only guess, ... So you're comparing what's there as HTML with what's there as PDF. ... most part demonstrate the point of offering the user control over the ... graphic sizes, ...
    (comp.text.tex)
  • Security holes in Hotmail, Yahoo, and other webmails
    ... Most webmails services and applications have huge security holes on the ... execution of malicious javascript and HTML code ... some parts of the user's mailbox, without use of javascript. ... Cross-site scripting vulnerabilities on the yahoo.com domain was reported ...
    (Vuln-Dev)