A LIST Apart: For People Who Make Websites

No. 194

Discuss: JavaScript Triggers

Pages

 <  1 2 3 4 5 >  Last »

21 Awesome

This is absolutely ass-kicking awesome. Finally some frigging seperation. W3C can you hear us. These are the kinds of things app developers want.

posted at 02:00 pm on February 1, 2005 by dru

22 don't confuse behavior and javascript

I think the article makes a lot of sense, but I think that it’s important to realize that not all javascript is behavioral. There is plenty of useful presentational javascript, such as Image Replacement and TOC Generation (to use two examples from PPK’s site).

I think the best practice for implementing PPK’s suggestions is to use custom attributes for behavioral javascript triggers, but not for presentational javascript triggers. For example, I think it would be fine to latch a JIR routine, for example, onto a ‘class’ attribute, because JIR is presentational. (Of course, you might want to keep your JIR routines — and all your presentational javascript — in a separate js file from your behavioral javascript).

Thoughts?

posted at 03:22 pm on February 1, 2005 by sam

23 Why is inline script better than intrinsic events?

You miss out some important problems, if you add behaviour to your html outside of the HTML, there’s a time period where the user can interact with the HTML without the proper behaviour, either they’ll trigger the no script fallback – which could be annoying they get a much worse user experience, and you’ve wasted your time writing the script. Or as is more likely for the majority of readers, they’ll get a load of nothing happening.

The delay in behaviour loses one of the key elements of UI that of consistency.

You can of course author your script in such a way that this isn’t a problem, however to do that you can’t abstract out your scripts, they have to be inline next to the elements and immediately follow the HTML elements they’re modifying.

Seperating script and HTML simply isn’t practical in todays mark-up languages. Simple onsubmit form validation might cut it, just about, because the user is unlikely to interact with the form enough until after the behaviour has been attached, but the more complicated validation that provides real-time feedback, that’ll be down the same problem of “onload=‘someformelement.focus()’” where most users are well into the field before being viciously snapped back to the first.

posted at 03:47 pm on February 1, 2005 by Jim Ley

24 Inline scripts and onload

Jim, what you’re really saying is that the load event is not good enough, since it may fire too late.

I completely agree, but I don’t know what to do about it. I assume a solution will be found one day.

Meanwhile we should solve the problems we can solve.

posted at 04:25 pm on February 1, 2005 by ppk

25 XML namespaces?

Would use of XML namespaces be a more appropriate solution for marking up elements with purpose-specific triggers than forking an XHTML DTD?

posted at 04:32 pm on February 1, 2005 by Sean Upton

26 XmlHttp

Why choose custom attributes & custom DTDs over simply storing the information in a remote XML file, and loading it via XmlHttpRequest?

It seems to me that in the case where a class can’t hold necessary information (eg, your textarea length example), it would be simpler to add ids to the elements in question, then load a remote file which ties the id to the data being imparted. Indeed, in more complex cases this could prevent a serious outbreak of attribute-itis in your html.

And if you were going to follow such a path for different scripts, it’d be fairly trivial to develop a small library which could be told the files to load, and return data: value combinations tied to specific ids.

posted at 04:33 pm on February 1, 2005 by Lach

27 XML Files

Lach,
It’s interesting you mention this because I am in the middle of implementing such a feature at my work. I built the server-side validation to utilize an XML file for required field information, error text, regular expression patterns to run against form values, etc…

This approach allows the ability to utilize Javascript to pull the XML file and validate the form in the browser using the same logic that is used on the server.

In this article, PPK is primarily discussing attaching triggers to input controls (like a textarea). While using an XML file for validation is a great idea for error messages, required field and such, it does not help with attaching triggers to controls (to monitor max lenght as text is typed).

posted at 04:44 pm on February 1, 2005 by Justin Perkins

28 inline scripts and onload

PPK,

Yes the point is that onload is too late, even Google’s very simple page, I often run into focussing problems (where I’ve already entered my search term and have tabbed to a submit button before I get focus’d back onload.

The other parts of the idea, using attributes to encode validation values etc. and how to validate those is very useful techniques. However I don’t think we should advocate not having a onsomething=“dosomething()” in elements that should have behaviour, there’s great arguments for generalising dosomething as much as possible, but because user behaviour is degraded with the onload techniques, we hurt ourselves more than we gain.

One of the problems of this is that it’s something that’s so rarely picked up by developers or their testers, they tend to have cached pagesm and good local connections – even if they test with a bandwidth limiter on, they rarely test with a simulation of the wifi suddenly disappearing so image number 5 isn’t downloaded until much later than normal.

So take the idea of validation of abstracting out values into the markup, but please leave your intrinsic event in the document! Your users will thank you.

posted at 05:20 pm on February 1, 2005 by Jim Ley

29 XForms

Once XForms is supported by major browsers, the need for this sort of thing will go away. At one point while writing the DTD article, I was thinking of writing a JavaScript that would go through an HTML file that had XForms elements in it, and rewrite it to replace them with HTML elements and calls to appropriate JavaScript. Then I realized I didn’t have time to write a master’s-thesis-level program (XForms has lots of options).

posted at 05:39 pm on February 1, 2005 by J David Eisenberg

30 XML Files?

Seems to me that storing all that data in an external file and loading it via XMLHTTP is like going all the way to china just for noodles. You can get them at the grocery store. Don’t separate too much; as PPK says Keep it Simple. After all, PPK is just extensifying a page. It would be silly to call a language ‘eXtensible’ without being able to extend it, wouldn’it?

posted at 06:44 pm on February 1, 2005 by Dante

Pages

 <  1 2 3 4 5 >  Last »

Discussion Closed

New comments are not being accepted, but you are welcome to explore what people said before we closed the door.

Got something to say?

Discuss this article. We reserve the right to delete flames, trolls, and wood nymphs.

Create a new account or sign in below if you’d like to leave a comment.

Remember me

Forgot your password?

Subscribe to this article's comments: RSS (what’s this?)