<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:content="http://purl.org/rss/1.0/modules/content/">

    <channel>

    <title>A List Apart: Comments on: JavaScript Triggers</title>
    <link>{url_title_path=articles/}</link>
    <description></description>
    <dc:language>en</dc:language>
    <dc:rights>Copyright 2012</dc:rights>
    <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    <admin:generatorAgent rdf:resource="http://expressionengine.com/" />




    <item>
      <title>Posted by: Woolly Mittens</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/#1</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#1</guid>         
	  
      <description><![CDATA[I've been poking into this method of seperating the functionality from the markup too. I scan the document for certain key classnames and I add fun little event handlers accordingly. You might want to have a look over here: http://www.woollymittens.nl/content/weblab/lib_classbehaviour]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Adrian Holovaty</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/#2</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#2</guid>         
	  
      <description><![CDATA[I'm interested in hearing more reasoning about why "the class attribute should only be used for CSS," as I've used classes for unobtrusive JavaScript for a while now and find it to be an incredibly useful technique.

It seems like it's not worth the hassle to create a custom DTD just for the sake of adding custom attributes. What's really that wrong with using classes?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Dante</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/#3</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#3</guid>         
	  
      <description><![CDATA[I hope you can hear my applause in the Netherlands, PPK. This is why I respect you so much, for insight like this. Great!!]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Jacob</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/#4</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#4</guid>         
	  
      <description><![CDATA[Isn't this a bit of a slippery slope?  What is the point of writing to standards if you are just inventing your own?  I agree with Adrian, it doesn't make sense to go to the trouble of reserving Class attributes for CSS while creating ficticious attributes just for your javascript.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Jonas</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/#5</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#5</guid>         
	  
      <description><![CDATA["y[i].onmouseover = addBehavior" is non-standard (doesn't comply with ECMAScript or W3C DOM). The right way to do it is to use addEventListener(). Internet Explorer doesn't support addEventListener(), though (as most web developers know, it lacks support for a lot of W3C-standardized stuff). The solution is to try the standards-compliant way first (which modern browsers such as Firefox, Mozilla, Konqueror, Safari, Opera, etc. support), and - if that doesn't work - fall back to the non-standards-compliant method:

try &#123;
    y[i].addEventListener('mouseover', addBehavior, false)
&#125;
catch (exception) &#123;
    y[i].onmouseover = addBehavior
&#125;]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Dave S.</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/#6</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#6</guid>         
	  
      <description><![CDATA[Adrian's question is my question: I'd like to see some more reasoning behind why the currently-valid class attribute shouldn't be used for scripting. 

The separation of structure/presentation/behaviour doesn't appear to benefit any more from custom attributes than it does from 'misused' classes. The spec -- http://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.2 -- clearly states that the class attribute may be used for style, but also that it's open for general usage. The latter implies to me that using it for scripting is not a huge stretch.

Further, saying that custom attributes clear up the issue of stating 'deploy behaviour here' that classes introduce is simply untrue. The same argument applies equally to both applications. Your final result in both cases is an indication point in the markup for your script to tie into, you're simply introducing new syntax.

Your suggestion of custom attributes and a custom DTD forms a perfectly valid, future-compatible solution. I just think it seems more trouble than it's worth.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Dave S.</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/#7</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#7</guid>         
	  
      <description><![CDATA[Good article, by the way. I'm glad we're talking about this.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Justin Perkins</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/#8</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#8</guid>         
	  
      <description><![CDATA[I've struggled with this very problem and because I didn't want to add custom attributes I opted for the class method. I don't think I would have ever thought of creating a custom DTD, but now that the point has been made it seems like a no-brainer.

I always felt as though it was always a hack to use class names for custom Javascript behavior, this easily solves the problem. I don't agree that adding a custom DTD to *extend* the XHTML DTD is bad, I think that is the entire idea behind the the standard allowing the ability to specify your own DTD.

Great work Peter-Paul, this really opens a lot of doors for interactive forms and such.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: ppk</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/#9</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#9</guid>         
	  
      <description><![CDATA[Dave, Adrian, Jacob,

The reason I use custom attributes is exactly the one outlined in the article: it may become too complicated to read out all required information from the class attribute, and besides the required JavaScript code becomes simpler.

I have a form validation module that reads out a custom attribute I may define on any form element:

validate="required numerical date"

which means: "this field is required, it must contain a number and it's part of a date". My module reads out all values the custom attribute and then performs the necessary checks one by one: first required, then numerical, then date.

I can be certain that all values of the validate attribute have something to do with the form validation process, but I cannot be sure of all the values of the class, which will probably contain one or more CSS triggers.

It can probably be done, but I feel my solution is more elegant. Feel free to disagree, of course. This is a subjective argument and cannot be conclusively proven one way or the other.

Dave:
"Further, saying that custom attributes clear up the issue of stating 'deploy behaviour here' that classes introduce is simply untrue."

Correct, and I didn't say that. 
They clear up the issue of sending extra information ("maxlength is 300") to the script, something that can be done with classes, but not as easily or as elegantly.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: mateo m</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/#10</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#10</guid>         
	  
      <description><![CDATA[The main advantage of using custom attributes is that, as the article explains, it allows you to have multiple values passed to your triggers. For example, using custom attributes, you could define a number of validation rules for each form element, like 'require 2-10 integers', which would be pretty messy using the class attribute. So in my opinion, only in the simplest of cases is a custom DTD more trouble than it's worth...]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Charles Martin</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P10/#11</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#11</guid>         
	  
      <description><![CDATA[I did appreciate this being brought up as it has been lingering deep in the back of my mind since just about every job I've had required doing development specific to IE alone (either Intranet applications or B2B where it could be dictated what was required).  Thus, when coding for IE, who gives a flying flip about standards?  
However, I find myself much more leery of jumping into the same scenario when adding javascript and such to my personal website.  At some point, we all realize that we have to break the rules somewhere.. whether rules written down by some "authority" on web standards or rules we have laid out for ourselves when developing.  What complicates the whole issue is NOT just because the development of web-based applications is limited, but because the demands are on as web developers to jump over those limitations.
Some of the most nightmarish code I've dealt with was because of hearing the phrase "this would be cool.. do you think we can do it?"  It wasn't a matter of whether or not it was standards-compliant, we just couldn't back down from a challenge.  So we do the cool... and somehow lose a piece of ourself because we broke the rules.
The demands on web developers are growing, while the framework we use is remaining stagnant (due to slow acceptance of the newest standards and lack of standards-happy innovation among browser-developers).  Now I'm gonna go curl up in introspective silence.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Justin Perkins</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P10/#12</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#12</guid>         
	  
      <description><![CDATA[So, somebody comes along seeing this article and is trying to add trigger events to their form controls. They are also trying to make the page validate as XHTML, so they think they probably shouldn't use the "onclick" methods to attach events.

Then they see this article and decide to create a custom DTD that allows "onclick" to be in the attributes.

That would be funny.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Michael Havard</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P10/#13</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#13</guid>         
	  
      <description><![CDATA[We've been doing this for a few years now. It helps a lot with validation being able to say 'class="required string"' which then we can apply a certain style to and coopt to use with automated scripting routines. We do alot of this using scripting to either look at the document structure to attach behavior or looking into the classes and other properties for cues as to where to attach functionality. I.E. we have a div with a class="section" which has other divs and headings underneath to show subsections of content. When the class is changed to "section tabpanel" then the script kicks in and attaches clicks to the headings and arranges them in a tab panel format, hiding and showing the sections depending on which heading is selected. It allows for a great deal of customization without touching the content or content structure. It's great to see an article on the process finally.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Woolly Mittens</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P10/#14</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#14</guid>         
	  
      <description><![CDATA[If you're going to write a custom DTD just to add the attributes you need to bolt your event handlers onto. Then why not just add attributes like "onmouseover" and be back where you started?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Will Rickards</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P10/#15</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#15</guid>         
	  
      <description><![CDATA[I think the use vs not use the class attribute debate comes down to this.  Using custom attributes leads to cleaner, easier to read html/xhtml code.  I have no idea if this makes it more semantic.  It probably also leads to less javascript code as the article demonstrates.

I won't bother creating a custom DTD.  I don't think it is worth it.  I know my code is valid.    

Thanks for the great article and the great site.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Kamil &quot;Brego&quot; Dzielinski</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P10/#16</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#16</guid>         
	  
      <description><![CDATA[No. Why? Because the meaning of the article was separating js-logic from data. The problem would be solved by adding some extra DTD-based attributes - but it would be re-invented if one would add an event-handler to it.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Bobby van der Sluis</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P10/#17</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#17</guid>         
	  
      <description><![CDATA[Although in this case there are different ways of achieving the same goal, I think Peter gives enough arguments why using classes for JS triggers isn't the most optimal method.

Is his method better? I think so. Besides the fact that it is cleaner, I think it is pretty future oriented. If you look at WHATWG Web Forms 2 specs you will see that a lot of new attributes for 'built-in behavior' are in the pipeline.

By using your own custom attributes, you could already get used to this way of coding, and if you do it well, you could even use JavaScript to move into a more seemless future.

Peter-Paul and David, kudos for these two articles (great tag team), I enjoyed reading them.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Jonathan Broome</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P10/#18</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#18</guid>         
	  
      <description><![CDATA[Great articles, PPK & David.

In favor of custom attributes, I like that while you tweak the DTDs to your favor, it cuts out parsing strings or remembering why the class attribute contains 'fake' info that shouldn't be removed or re-ordered lest my quickly-poorly-coded parser quit working.

Even though it's convenient when a 'required' class in the attribute both colors the field background and triggers js on the element, I run into so many one-off validation requirements (e.g. "this required if that=x") that the class approach gets messy, fast.  At least with custom attributes the mess is confined/self-explained.

Two questions:
Do browsers tend to cache the custom DTD info once it's read, or is it requested with each page?  Caching makes sense, just wondered if anyone knows for sure.
If it caches, is that per session or do I have to worry about future visitors not getting version 2 of a tweaked DTD unless I rename it?
]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: ppk</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P10/#19</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#19</guid>         
	  
      <description><![CDATA[Jonathan, browsers do not load the DTD at all.

Bobby, you're completely right. Web Forms 2.0 is a powerful argument in favour of custom attributes.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Pork Chop</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P20/#20</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#20</guid>         
	  
      <description><![CDATA[Personally, I think the idea is a good one and don't see how it deviates from web standards. XHTML is an XML language, afterall; and so, in the spirit of XML, go ahead and create your own attributes if they suit your needs. As long as they are supported in your DTD, all standards are essentially being followed, no?

In any case, excellent idea that brings up an issue that it sounds like a lot of developers (including me) have been trying to tackle.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: dru</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P20/#21</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#21</guid>         
	  
      <description><![CDATA[This is absolutely ass-kicking awesome. Finally some frigging seperation. W3C can you hear us. These are the kinds of things app developers want.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: sam</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P20/#22</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#22</guid>         
	  
      <description><![CDATA[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?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Jim Ley</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P20/#23</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#23</guid>         
	  
      <description><![CDATA[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.

]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: ppk</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P20/#24</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#24</guid>         
	  
      <description><![CDATA[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.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Sean Upton</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P20/#25</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#25</guid>         
	  
      <description><![CDATA[Would use of XML namespaces be a more appropriate solution for marking up elements with purpose-specific triggers than forking an XHTML DTD?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Lach</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P20/#26</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#26</guid>         
	  
      <description><![CDATA[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.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Justin Perkins</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P20/#27</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#27</guid>         
	  
      <description><![CDATA[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).]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Jim Ley</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P20/#28</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#28</guid>         
	  
      <description><![CDATA[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.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: J David Eisenberg</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P20/#29</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#29</guid>         
	  
      <description><![CDATA[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).]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Dante</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P30/#30</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#30</guid>         
	  
      <description><![CDATA[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?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Davids Schontzler</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P30/#31</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#31</guid>         
	  
      <description><![CDATA[I'm a bit surprised only one person mentioned XML namespaces. It's a much more convenient way to add on what you need without have to decloare your own DTD. I'd argue that going the custom DTD route isn't worth the trouble since browsers rely on DTDs to determine what rendering mode to use. I'll warn you that, if I recall correctly, you have to use slightly different scripting to deal with namespaces in the major browsers.

Personally, I'm all for throwing in custom attributes and walking away. Parsers look for well-formedness, not DTD validity (except for in extreme cases). It's easy enough to ignore extra info, just don't break my parser!

Sidenote: It's nice to see a decent JS article on ALA. Cheers.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: David</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P30/#32</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#32</guid>         
	  
      <description><![CDATA[enough said

(great article!)]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: stylo~</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P30/#33</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#33</guid>         
	  
      <description><![CDATA[&gt;&gt;storing the information in a remote XML file, and loading it via XmlHttpRequest?

Why xml? Far better and lighter and more crossbrowser, just have your classes detailed in your js file that is doing the validation, or a 2nd js data-only file. Then your js is truly separate, not half spilled around various html attributes, and half in js files. On second thought, wouldn't you agree, PPK?

Who said class is only for css? The id attribute isn't only for css, but is used by both js and css. Also, classes do seem best for this to me because most of this info is being reused, thus truly classes (if not use, the id). With custom attributes, you have to change each individual one during upkeep, like old font tags, rather than update your class definition in your js file. 

If you really must include data in the class itself, you can use classes like js-classname-data and then pickup all "js-" classes and split them in js. Very easy.

Finally, anyone who uses custom attributes (and maybe best in certain cases anyway) then goes to the trouble of writing a custom dtd to tell a computer at w3c to ignore certain items he already knows to ignore has too much time on his hands and hasn't really thought about what he's doing. -Unless of course he's being paid to do exactly that :-)

Personally, I wouldn't use xhtml either, but that's another article...]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Joel Bernstein</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P30/#34</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#34</guid>         
	  
      <description><![CDATA[If you can assume that each element has only one behavior, you could simply define a "scriptclass" attribute which would behave like a class attribute but not be stylable.

The main benefit over the method in the article is that you wouldn't have to update your DTD every time you write a new behavior.

It might even be possible to use a comma-delimited list of behaviors that gets parsed on page load, though you'd have to be sure your function parameters don't intersect with each other, and it wasn't too bad of a performance hit.
]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: A very appreciative student</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P30/#35</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#35</guid>         
	  
      <description><![CDATA[Wow just wanted to comment with how useful ALA and this article have been in helping me develop to standards and create very efficient code. I learned from here much more than tens of credits at WWU.

Thanks!]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Justin Perkins</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P30/#36</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#36</guid>         
	  
      <description><![CDATA[In regards to Dante's comment about too much separation being a bad thing... 
The thought is that if you're going to perform server-side validation *and* client-side validation, why wouldn't you abstract the validation out of the code for an ease of maintenance standpoint?

My vote is for dependency, but there are those that prefer to be redundant and that is fine. There are pros and cons to each.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: peterned</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P30/#37</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#37</guid>         
	  
      <description><![CDATA[It's good to think about proper script triggers without polluting the markup, but I strongly disagree with the class attribute being a presentational attribute. The . and # are merely shortcuts for doing the same thing with the attribute selector. In a way that makes it ironic that IE only supports the shortcuts, and not the generic way. 
See also: http://www.rikkertkoppes.com/thoughts/class-and-style

Attributes values (where I'd prefer the class over a custom one) are ok for basic validation, but complex rules that involve multiple fields cannot be defined with a mere attribute value. Interpreting any of these things requires javascript, so the more you define in html itself, the more you actually mix structure and behavior. Since clientside validation is only an indication for the user - a server should never rely on it without checking for itself - it should be treated as behavior: I'd opt for writing as much of the validation as possible in a separate script file.

This doesn't mean that I think this is a bad article mind you ;) It's an important concept, and the right way to go. But I do think the examples chosen to show how to use triggers between the different application layers could have been better.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Martin</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P30/#38</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#38</guid>         
	  
      <description><![CDATA[At the start of your article I noticed this particular sentence: "For instance, it should be possible to rewrite the entire presentation layer without touching either the structural or the behavior layer."

However at the end your conclusions lead to a method that requires you to accually hack back in all the validation rules for the form if you decide to rewrite your structural layer. Oh and now that I mention the form, where's the usefull information about generic javascript-triggers that the title implies, all I've found so far is an article about form-validation, which should not be included in the structural layer and more than you should have classes like: 'class="boldRed"'

CSS reacts upon structural data, some of that data is expanded by id's and classes which are two ways of providing extra information about the structure. For instance a class can explain to the CSS-parser that a couple of groups of structural data are of a similar kind and thus can have similar presentation applied.

A behavioural layer should react upon events in the structure of a document, investigate if it is of a nature that it needs to react and if not become dormant again. All the information that needs to be supplied for writing a behaviour is already in the structure, even in forms.
The structure can tell the behaviour that the key-press occurred in a text-area and what the name of the text-area is, a well-written behaviour could now, easily, determine wether or not the maximum length of the textarea is breached, even if the entire presentation is changed.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Michael Ward</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P30/#39</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#39</guid>         
	  
      <description><![CDATA[If extending XHTML by adding your own attributes, you should be careful that you're not specifying an attribute that is going to popup in a future spec with a different meaning.

Try adding a prefix that is likely to be used in the formal spec (think of Mozilla's -moz- css3 implementations).

Other than that, I feel quite comfortable using the class atribute as a hook.

class="required large" could receive both the correct styling from CSS and behaviour from Ecmascript.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: AkaXakA</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P40/#40</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#40</guid>         
	  
      <description><![CDATA[// "I think it is pretty future oriented. If you look at WHATWG Web Forms 2 specs you will see that a lot of new attributes for 'built-in behavior' are in the pipeline." //

No. As Michael already noted, it might be used in futurespecs. What might be worse is that it might be used _in an entirely different_ way.

Also, as others have said classes _are_ to be used for this kind of thing, not to mention that you can reuse them in your CSS. Reusing them will also mean that your CSS and JS will be easier to understand together, as they'll both be using the same names for the variables.

That said, the basic idea of not using "onMouseOver" attributes is a excelent one.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Nick Fitzsimons</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P40/#41</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#41</guid>         
	  
      <description><![CDATA[I've come to the conclusion from experience on several recent projects that using XML namespaces is the cleanest way of using custom attributes in XHTML. After all, that's what namespaces are for - to allow one to mix elements/attributes from various types of document while making it clear which comes from where.

This also takes care of the question of attributes of the same name turning up in a later version of whatever standard - my nf:required="true" attribute won't ever be the same as any other "required" attribute, as they live in different namespaces.

Totally off-topic, does anybody know why there's no "Preview" button on this form?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Jürgen</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P40/#42</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#42</guid>         
	  
      <description><![CDATA[Hello there,
I guess I am dense, but I can't get that to work. Only worked in IE (ugh). Could someone point me to some more real-life examples how it gets implemented?

How should I understand that line here: 
y[i].onmouseover = addBehavior;

I tried 
x[i].style.behavior = 'url(htc/externallink.htc)';
which made it work in IE, I guess.

thanks
]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Adrian</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P40/#43</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#43</guid>         
	  
      <description><![CDATA[This is a very clean and semantic-rich way of going about things. I love it.

My only complaint is that class="required" is a better way to go -- it signifies this input belongs to the group of elements that are required. 

However you won me over with the maxlength attribute. Well done.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: TC</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P40/#44</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#44</guid>         
	  
      <description><![CDATA[The described approach has its merits however there is an alternative that I believe is more versatile and no more complicated…

Although these comments may strike fear into the hearts of some developers, especially those that aren’t familiar with OO concepts and patterns, it really isn’t as complicated as it sounds.

I take a slightly alternate view (having come from a more traditional GUI development background), which in recent years has become widely recognized as the Model View Control (MVC) pattern. I believe that this pattern can be used at many levels of granularity. For instance it could be applied to a single user interface (UI) component/widget or the entire UI. Basically the HTML in combination with CSS can be considered to be the “View” and JavaScript can be used to implement the “Model” using classes (OO classes, nothing to do with the HTML class attribute). By “modelling” UI components with instances of JavaScript objects it is possible to give them any behaviour you desire. For example, in order to address the issues discussed in the article a TextField class could be written with methods and attributes (local variables) to support validation. There are numerous ways to implement and exploit this technique (the choice will depend on the complexity of your site and your use of JSPs etc.) however one simplistic approach is to create an instances of the class for each UI component that requires it, in our case, for each input field. Attributes such as “required”, “numeric”, “max length” etc. can be set either through the class constructor or via setter methods. i.e. 

&lt;input name="name" class="required" /&gt;
[removed]
    textFields[textFields.length] = new TextField(“name”, true, false, 10);
[removed]

It should be noted that this approach is extremely versatile and isn’t limited to one object per HTML element. Several complimentary HTML elements can be combined together to form a “super” component. The TextField class, for instance, could be given the ID of an associated “img” element that can be set according to the status of the input field. I believe that Tapestry (part of the Apache Jakarta project http://jakarta.apache.org/tapestry/) takes this approach to the framework level.
]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Dave Cardwell</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P40/#45</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#45</guid>         
	  
      <description><![CDATA[Is the structure layer the appropriate place to stick constraints on user input?  For example we could add a 'mask' attribute using the methods described in this article to do something like the following...


&lt;!ATTLIST input mask CDATA #IMPLIED&gt;

&lt;input id="name" mask="^\\w+(\\s\\w+)+$" /&gt;

if( obj.getAttribute("mask") ) &#123;
    var re = RegExp(obj.getAttribute("mask"));
    if( !obj.value.match( re ) ) &#123;
        // do something about it
    &#125;
&#125;


Name isn't a particularly good one to constrain since there are too many different styles of name, but it makes for an easy example.



And how about things like:

&lt;!ATTLIST input confirms IDREF #IMPLIED&gt;

&lt;input id="pass" type="password" /&gt;
&lt;input id="pass_conf" type="password" confirms="pass" /&gt;

if( obj.getAttribute("confirms") ) &#123;
    if( obj.value != document.getElementById(obj.confirms).value ) &#123;
        // do something about it
    &#125;
&#125;



Do these examples belong in the structure or the behaviour?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Laurian Gridinoc</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P40/#46</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#46</guid>         
	  
      <description><![CDATA[By a custom DTD you register an element or attribute in a namespace you don't own, doing it by DTD is more like to validate the page, but the new element/attribute semantics does not belong in the current/default namespace.

I would go for custom CSS declaration for behavior and not for a custom attribute, something like:
#superInput &#123;
    foorequired: true;
    foomask: regexp;
&#125;

and have the javascript access this information somehow (see http://www.kryogenix.org/code/browser/jses/)

Or have the behavior in a RDF file, ie. using URIs for element IDs, and a javascript parsing the RDF and applying the rules (ie: see function ui() from http://www.grapefruit.ro/ui/script/grapefruit.js and the RDF http://www.grapefruit.ro/ui.xml).]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Will Rickards</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P40/#47</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#47</guid>         
	  
      <description><![CDATA[Interesting point about the load event happening too late.  It really is convenient just having to modify the .js file though.  Kind of like just having to modify the .css file.  But this practical issue may change some of my implementations.

However, inline scripts have another disadvantage, that is that other elements they need to reference might not have been loaded yet at the time they are invoked.  This leads to much more defensive coding and probably more code.

For forms, this is why I prefer to validate all the fields again in the onsubmit handler.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Jim Ley</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P40/#48</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#48</guid>         
	  
      <description><![CDATA[Will, onload firing is no guarantee that your elements are there and scriptable - try pressing the stop button as the document is loading - onload still fires.

For me there's no extra defensiveness inline to onload, they're as equally likely to fail.

]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Michael Kowalski</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P40/#49</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#49</guid>         
	  
      <description><![CDATA[I've been using this kind of technique a lot in the last couple of years and found it very useful for code reuse on web application GUIs. That's a practical benefit rather than a theoretical one.

One thing in favour of CSS class names is that you typically want to give the user a visual cue for whatever behaviour that you're adding to a control. As IE doesn't support attribute selectors, you have to use a class name for this anyway. 

I tend to attach a standard prefix (say, "ui-") as a kind of bogus CSS "namespace" to differentiate behavorial class names from purely presentational ones. 

Here's an example:
 &lt;input type="text" class="ui-date ui-required" id="birthday"&gt;
This INPUT will get a standard width to indicate it's a date control. Also the "ui-required" class name tells the javascript layer to flag an error if you try and submit the form without populating this control. 

I've built some pretty complex client-side controls like this (collapsible trees, etc, as well as a more or less complete implementation of the new WebForms 2.0 input types).

But I agree that CSS is not such a good approach for adding behaviour like RegExp validation.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Eric Moritz</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P50/#50</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#50</guid>         
	  
      <description><![CDATA[Dean Edwards of IE7 fame, has an awesome javascript function called cssQuery. It allows you to select elements by css selectors.
http://dean.edwards.name/my/]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Joe Theory</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P50/#51</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#51</guid>         
	  
      <description><![CDATA[using the first simple div example verbatim the event fires for each element right when the document loads.  so that if i have 

y[i].onMouseOver = alert&#40;"yo"&#41;;
 and 4 &lt;li&gt; elements as in the example i get 4 alert windows upon loading the page.

after that, mousing over the elements dosnt trigger any action.  this is true for both firefox and IE though in IE it only pops up 1 alert.

any thoughts on what im doing wrong? thanks]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: sam</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P50/#52</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#52</guid>         
	  
      <description><![CDATA[nice link.  i was in the middle of trying to write that very thing.  i'm glad to find out its (a) been done (b) by a better coder.

combine cssQuery with a js that parses css files and there's some nice potential for extending css via presentantational javascript.

perhaps do JIR, for example, by using a custom "replace" css attribute

a.button
&#123;
   replace: url("images/mycoolbutton.png");
&#125;

cssQuery selects, another script parses the css and does the image replacement.  meanwhile the variable presentational elements are tucked away nicely in your css file.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Eric Moritz</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P50/#53</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#53</guid>         
	  
      <description><![CDATA[I thought that we were seperating the behavioural from the structural. Isn't putting a maxwidth="20" in the tag defining the behaviour?  If you had to change the behaviour of accepting 30 chars instead of 20, then you would have to modify the structural data.  That doesn't seem right to me.
It would be better to refer to that element by it's name or id in javascript. And apply the restriction of 20 chars directory in Javascript.  Then if you need to modify the behaviour you can leave the xhtml allow and only modify the javascript.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Michael Havard</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P50/#54</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#54</guid>         
	  
      <description><![CDATA[I don't know, to me maxlength defines the structure of the input first (how many characters can be held) and the behavior second (what happens if it goes beyond x characters) and lastly visual style (how does it display when rendered). Much like how the type attribute defines what the control will be (text/radio/checkbox). 

There are plenty of such properties that skirt the line of providing some aspect of structure, behavior, and visual styling. Those properties could be considered convenience properties in that they help impliment all the levels without needing to invoke some other language (js, css). This allows for the document to mean something to user agents that don't have the ability to use / or poorly impliment those other languages.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: dave</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P50/#55</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#55</guid>         
	  
      <description><![CDATA[BeCSS is an interesting, related technology that stalled awhile ago:

http://www.w3.org/TR/1999/WD-becss-19990804]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Dante</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P50/#56</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#56</guid>         
	  
      <description><![CDATA[The replace property has been added in CSS3 under the name of the icon property. For example:

h1 &#123;
display: icon;
icon: url(image.gif);
&#125;

is the CSS3 way to do Image Replacement. No browser supports it yet, though.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Paul Roe</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P50/#57</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#57</guid>         
	  
      <description><![CDATA[Great article, and I have been using this technique ever since I read the article on "usable forms" on your web page. Thank you Mr. Koch for all of your contributions.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Ash Searle</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P50/#58</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#58</guid>         
	  
      <description><![CDATA[Mr Koch notes that javascript code will quickly become complex when trying to parse class attributes like "phone minlength=13 required".  As a suggestion for handling this, I'd suggest this function:

    function readSpec(classs) &#123;
        var f = function (a) &#123;
            return a.match(/=/) ? a.replace(/=(.*)/, ":'$1'") : a + ":true";
        &#125;
        var o;
        return eval&#40;"o=&#123;" + classs.replace(/\S+/g, f&#41;.match(/\S+/g) + "&#125;");
    &#125;

This turns the class attribute into an object, allowing you to write more easily maintained code such as:

  var spec = readSpec(inputField.className);
  if (spec.required) &#123;
    // check non-empty...
  &#125;
  if (spec.minlength &gt; 0) &#123;
    // validate input data...
  &#125;
  if (spec.phone) &#123;
    // phone number validation
  &#125; else if (spec.email) &#123;
    // email validation
  &#125; ...etc...

]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: DEfusion</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P50/#59</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#59</guid>         
	  
      <description><![CDATA[Your content layer is now dependent on your behaviour layer.  Say you want to scrap all your behaviour - instead of just removing the behaviour scripts you now have all this junk laying around whose only purpose is to support the old behaviour layer.

I created a reusable validation script, which seems to be a regular example of usage of this method in this discussion, and all it relies on is field IDs. The information on how each should be validated is related to the behaviour layer only - so there is an external XML config file which the validation script uses in combination with IDs.

I've never found it a problem to use IDs and classes for behaviour layer hooks/triggers, as far as I see them they are not exclusivly the domain of CSS, they're just their to identify unique elements or groups of related elements - thats it.

I see adding a custom attribute required="true" to be the same as applying a color="red" attribute - it just doesn't belong in the content.  The content shouldn't know or care about behaviour or styling.

-D]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Austin</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P60/#60</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#60</guid>         
	  
      <description><![CDATA[This is an interesting debate.  

Is maxlength="30" behaviour or structure?  I think we can probably agree its not presentation.

If its behaviour, then it should not be an attribute of the element, it should be in a .js somewhere or perhaps in an external .xml

I dont like the class method much but can see the argument for using it, take the example of classing elements that are required.  ie. class="required".  Its a valid class. Taking that further then I suppose it is valid to clasify or group all content with a maximum length of 30, ie. class="maxlength=30", but I do think the class method does get a bit messy.

I started out having read the article and having used the technique before, agreeing with the author, but after reading all the comments I find myself agreeing with both all three view and unsure if there is a right way or a wrong way.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: R Cotton</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P60/#61</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#61</guid>         
	  
      <description><![CDATA[The article includes a few problems to my mind, which have been touched on, but not properly followed through.

The concept of seperating behaviour and presentation from structure is slightly incorrect thinking from the very begining: they re NOT seperate, they are DRIVEN BY and hence coupled to the structure. (even in CSS the presentation of elements is constrained by their order in the structural document. i.e. no "float: top;", the structure constrains vertical positioning)

Second; the "id" and "class" attributes ARE NOT presentational triggers. They are unique and group identifiers, which are used by CSS to drive its specific rules, and which ca be used by javascript (or other things), to drive their activities. This is why we try to use classes like "product_description" rather than "justify center-block red bold larger".

Also remember that you write the structure document supplying semantically meaningful hooks on which to hang your other (presentation or behaviour) code. We should be using class to define as much semantic meaning as possible in a structure document; if you have a paragraph that has product description in it; set the class to "product_description" -- it is a seperate question whether there are any special style rules in CSS that you are actually going to set for that paragraph; its STILL got the product description in it! (this way you have MORE chance of writing a new pres. layer without touching the structure - CSS Zen Garden is a demonsration of this principle in effect) 

You are NOT required to only use class values in your structure that your CSS has rules for! Therefore you are at liberty to use some class values for behaviour hooks; they just get dealt with by the JS, not by CSS.

Finally, and fairly obviously to anyone who can actually program code, the parsing script shown is INFANTILE in the extreme. It should therefore be discounted as an argument for not parsing the class attribute.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: ppk</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P60/#62</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#62</guid>         
	  
      <description><![CDATA[DEfusion:
"Your content layer is now dependent on your behaviour layer."

Vice versa, actually. If the behaviour layer doesn't work (because the browser doesn't support JavaScript, for example) the structural layer remains accessible. On the other hand, the behaviour layer won't function without the structural layer.

"Say you want to scrap all your behaviour - instead of just removing the behaviour scripts you now have all this junk laying around whose only purpose is to support the old behaviour layer."

Possibly, but not necessarily. Just as you could scrap the style sheet but retain the classes and ids as triggers for the new CSS, you could retain the old behavioural triggers but rewrite the script.

If you see this as a drawback of custom attributes, would you also oppose the deletion and insertion of classes and ids when the presentation layer is changed?

Austin:
"Is maxlength="30" behaviour or structure? I think we can probably agree its not presentation."

Interesting question, and I don't readily have an answer. Is class="mainheader" structure or presentation?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: DEfusion</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P60/#63</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#63</guid>         
	  
      <description><![CDATA[ppk:

"If you see this as a drawback of custom attributes, would you also oppose the deletion and insertion of classes and ids when the 
presentation layer is changed?"

No, I agree with what R Cotton said.  Classes and IDs can be used as pseudo semantics specifc to your content, whether you are using these hooks for style/behaviour etc. does matter to the structure.  Without the style/behaviour layers being there a given 'product' can still have the class 'product' applied - I'm not sure the same goes for custom attributes.

Although I've never looked at it to the extent of adding IDs & classes prior to their requirements for style/behaviour I can see the advantages. 

-D]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: ppk</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P60/#64</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#64</guid>         
	  
      <description><![CDATA["Classes and IDs can be used as pseudo semantics specifc to your content, whether you are using these hooks for style/behaviour etc. does matter to the structure."

I see what you mean, and for something like "required" you might be right. Personally I don't think that "maxlength=300" belongs in a class, though, so that's where I draw the line.

Feel free to disagree, though. This is uncharted territory, and the more opinions we have the better.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Larry P</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P60/#65</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#65</guid>         
	  
      <description><![CDATA[Although I benefitted from this article's discussion about adding custom attributes, I would caution against using the term "triggers."

Traditionally, in comp sci when we refer to triggers, we are talking about items that trigger the invocation of an event or method, usually in response to an action.  Databases use triggers all the time after an insert or an update, for example.

In the context that the author is using them, his "triggers" are search terms, and perform no more triggering than any other identifier.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: ppk</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P60/#66</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#66</guid>         
	  
      <description><![CDATA["Traditionally, in comp sci when we refer to triggers, we are talking about items that trigger the invocation of an event or method, usually in response to an action."

Which, as far as I'm concerned, is a perfect description of what JavaScript usually does.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: DEfusion</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P60/#67</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#67</guid>         
	  
      <description><![CDATA[ppk:

"Personally I don't think that "maxlength=300" belongs in a class, though, so that's where I draw the line."

I agree, I don't think it belongs in a class, and in this instance it could be argued that it would be an example to extend the DTD.  However I personally would much rather have this behaviour config in something that's related to the behaviour - be it a xml or js config file.

The structure would have an ID/class associated with the field and the config would have any behaviour requirements associated with the ID/class.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: ppk</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P60/#68</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#68</guid>         
	  
      <description><![CDATA[But then the site would lose clarity. You'd end up with interminable arrays like

var maxLengths = new Array(
'story_of_my_life',1000,
'my_problems',300,
'my_cat',550
);

and that's a construct I'd rather not use. It's ugly and it doesn't allow newbie webmasters to easily change the maxlengths of textareas.

Besides, if the maxlength is the only behaviour associated with a textarea and we use a maxlength attribute, we don't need an id at all.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Rikkert Koppes</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P60/#69</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#69</guid>         
	  
      <description><![CDATA[You state that classes should only be used for CSS, this is not true.

Classes are an extension to the element's name. More like subgroups of elements.

However, I agree with the use of custom attributes in some cases. 

I've written something on classes once: http://www.rikkertkoppes.com/thoughts/class-and-style

point is, there is no specific attribute that is intended as a trigger for CSS, nor should there be for JS triggers. attributes should only be added if there is no other attribute that could indicate it's meaning (adding rel="external" for external links and applying some JS on that category is perfectly fine, no use for an extra attribute).

When defining attributes, keep semantics in mind, just as you would do by adding custom elements]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: a scuba diver</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P70/#70</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#70</guid>         
	  
      <description><![CDATA[One more step toward 100% semantic markup and no more behaviours in the XHTML. This article explained it brilliantly.

In CSS you can stack classes upon classes in your tag, so I can apply multiple classes selectively to my elements.
for example: &lt;div class="loud fresh inabox sideways"&gt;

Can the same method apply to behaviours?
For instance, can I use external scripts to control the status bar, turn up the volume of my flash movie, and replace an image, all in one go with class names representing each of those behaviours?

&lt;a class="gostat newimg louder"&gt;click&lt;/a&gt;

While most people put lots IDs and CLASSes in their html, some hard-core coders do not Get their Elements By Id. Instead, these hard-core semanticists iterate through the DOM numerically to apply a behaviour to the third link in the fourth table cell inside the first table inside body. It's only a matter of time before I have my CMS building javascript to apply styles and behaviours to elements without bulking up my code with class definitions.

We don't live in a classless society (yet), but I can build a classless website! (some would argue that most of my sites don't have class to begin with ;)
]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: R Cotton</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P70/#71</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#71</guid>         
	  
      <description><![CDATA["While most people put lots IDs and CLASSes in their html, some hard-core coders do not Get their Elements By Id. Instead, these hard-core semanticists iterate through the DOM numerically to apply a behaviour to the third link in the fourth table cell inside the first table inside body."

Err, no. Hardcore idiots do that. Add or remove a link, and you have to re-write the whole lot. Going down that route will be a (thankfully lonely) treck backwards for you. Good luck, more good luck to anyone needing to maintain your work!

The class attribute exists to classify an element; literally to note that it belongs to a type, which can have multiple members. The id attribute allows you to assign a unique identifier to an element. CSS allows you to add presentation rules based on these, by selectively taking parts of the article, you can use JS to add dynamic behaviour based on these.

To tackle the maxlength for a textarea example that recurs in this discussion, imagine that you have your textarea; for the sake of comparison with CSS, lets also imagine that you want to give it a red background.

The idea of redefining the DTD to allow a maxlength=300 attribute is directly analogous to redefining it to add a background=#FF0000 attribute; most people now prefer to add either a class or id to the textarea, then use CSS based on the class/id to add the background setting.

So, to follow through; add a class or id to the textarea, id if you feel it should be uniquely identified, class if you expect multiple 300 character limited textareas. Your javascript then adds the behaviour, based on the classification or identity of the element.

Remember that the example was NOT to create a textarea element structurally limited to 300 characters; it was to add the BEHAVIOUR to a structurally bland textarea that refuses characters after the 300th. It is the job of the behaviour-defining code to know the specifics of the bahviour you want; you should be altering the definition of the behaviour should you want to move to a 250 character limit, not every place the behaviour is invoked.

The paradigm in use in XHTML +CSS (+JS with this method) is to classify and identify "special" and meaningful elements in the structure, and then in the supporting source documents to assign extra instructions to them.

Move away from that paradigm, and it seems the natural inclination is to revert to specific instructions for presentation or behaviour in the structure document. Some seem less inclined to notice the reversion than others?
]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: R Cotton</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P70/#72</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#72</guid>         
	  
      <description><![CDATA["Is maxlength="30" behaviour or structure?"

IF the structural element supported having its length limited, it _could_ be structural; example an element for input of data that MUST be limited to 30 characters by its nature. Without that support, and specifically if you are using it to drive addition of behaviour, it is behavioural. (and therefore does not belong in the structure document)

I'm going to add a third example of my own, but in the middle;

Is align=justify presentation or structure?

Hopefully its pretty obvious that this is presentation, and does not belong in the structure document. This is why it has been deprecated over time.

"Is class="mainheader" structure or presentation?"

This is structural, and the right way to go about things. Replace "mainheader" with something else appropriate for a textarea, and it becomes reasonable to look at attaching both justified presentation and character limit behaviour to that element. Or nothing; because the classification is structural. It is because the classification is structural that we are safe to assign behaviour or presentation on its basis...]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Jim Ley</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P70/#73</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#73</guid>         
	  
      <description><![CDATA[A Scuba Diver

"While most people put lots IDs and CLASSes in their html, some hard-core coders do not Get their Elements By Id. Instead, these hard-core semanticists iterate through the DOM numerically to apply a behaviour to the third link in the fourth table cell inside the first table inside body"

Please, please don't do this!  It's a very bad idea, R Cotton has already talked about the maintenance problem, but there is another more serious one - Accessibility Aids, often have to modify the DOM of a document so it renders effectively for their users - perhaps adding links for them to get more info next to each image, or some extra elements to add DHTML too, or removing some elements to simplify the document.  

If you use gEBI type approaches, (or indeed JS triggers) then this is generally perfectly safe for them to do.  However assuming the DOM on the users machine is identical to the DOM on the developers machine is simply not a pragmatic choice.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: sam</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P70/#74</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#74</guid>         
	  
      <description><![CDATA["assuming the DOM on the users machine is identical to the DOM on the developers machine is simply not a pragmatic choice."

does that mean you can't use css parent, child selectors?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Puzzled</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P70/#75</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#75</guid>         
	  
      <description><![CDATA[A couple of readers have asked about this line in the first, simple example involving id's, with no response so far: "y[i].onmouseover = addBehavior;"
I too am confused.  PPK, what could you have in mind that both works across browsers and triggers for each mouseover?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: ppk</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P70/#76</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#76</guid>         
	  
      <description><![CDATA[I just want to show how you can go about adding event handlers to elements. I have no idea what addBehavior would do, that's something I leave to the fantasy of the reader. For this article it doesn't really matter.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Jim Ley</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P70/#77</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#77</guid>         
	  
      <description><![CDATA[Sam, I wouldn't call them reliable certainly, and I wouldn't use them on anything that relied on the functionality succeeding, e.g. position absolute on one element and then only give the background colour on the first-child, 'cos that could break.  but with CSS optional it hopefully should never break your page - remember users who are sprinkling elements throughout other peoples pages are more interested in the functionality they're gaining than what it looks like!]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Boris</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P70/#78</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#78</guid>         
	  
      <description><![CDATA[Anyway I don't think handling data validation should be done on clientside, don't you ?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Sainkho</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P70/#79</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#79</guid>         
	  
      <description><![CDATA[Firstly, I'm no expert, I'm no wood nymph, troll or flamer either. I'm always in awe of the articles and  discussions hereabouts but how come it took eight pages of chat before Boris stated what I always thought was the bleedin' obvious - validate client-side?

And secondly, in my naivety, what happens when the user doesn't have Javascript enabled?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: ppk</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P80/#80</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#80</guid>         
	  
      <description><![CDATA["Anyway I don't think handling data validation should be done on clientside, don't you ?"

Why not? As long as you also do it server side there's no problem. 

Client side form validation is more user-friendly, while server side form validation is safe. Combine the two and you get a user friendly safe application.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Svein Atle</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P80/#81</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#81</guid>         
	  
      <description><![CDATA[Of course, you should never rely on client-side validation only (or really any data coming from the client), but using it in addition to server-side validation may make your pages more userfriendly/comfortable.

Anyway, I don't think the purpose of the article was to show how to do client-side validation, but to discuss ways to seperate structure and behaviour.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Svein Atle</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P80/#82</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#82</guid>         
	  
      <description><![CDATA[... and now I look like I'm just rephrasing your  post ppk :/]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Sainkho</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P80/#83</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#83</guid>         
	  
      <description><![CDATA[Granted this article is about adding general functionality (with the chosen illustration of validation) but what if client-side scripting isn't available? Do those users lose out, with validation or whatever whizz bang is being offered by the technique?]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: ppk</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P80/#84</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#84</guid>         
	  
      <description><![CDATA[What if client side doesn't work? We leave it to  the server side script.

And... (now for the requested whizz bang) ...

The server side script can use *the same custom attributes* to determine which field should be checked for what!]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: DEfusion</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P80/#85</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#85</guid>         
	  
      <description><![CDATA["...but what if client-side scripting isn't available? Do those users lose out..."

No, that's the whole point of seperation of behaviour from structure.  In the same way that users can still see the content if they have stylesheets disabled when style is seperated from the content, they should also be able to access & use the content without the behaviour applied.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: DEfusion</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P80/#86</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#86</guid>         
	  
      <description><![CDATA["The server side script can use *the same custom attributes* to determine which field should be checked for what!"

This could also be said if you were using XML to determine which field should be checked for what.

]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Boris</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P80/#87</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#87</guid>         
	  
      <description><![CDATA["Why not? As long as you also do it server side there's no problem."

Sure, but what a peanuts work... I mean you work twice for nothing (I don't say user friendly is nothing).

It would be fun to try an httpRequest on form content when changed or submited in the way Google suggest works.
]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Larry P</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P80/#88</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#88</guid>         
	  
      <description><![CDATA[Not to get into a debate on semantics, and perhaps I do not fully understand how the author is presenting "triggers", but according to the article, the given example for an id "trigger" is:

var x = document.getElementById('navigation');
if (!x) return;
...

var x is first assigned to, then x in the boolean evaluation is being used as a flag, and we are taking action based on whether that flag is null. This is a typical branch: why would this be called a "trigger"?   

Every imperative language has this facility, it is not particular to JavaScript nor event-driven programming in general, and branching and taking action based on a condition is one of the fundamental ideas of programming. 

How are these "triggers"?  ppk, what am I missing?  


]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: R Cotton</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P80/#89</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#89</guid>         
	  
      <description><![CDATA[The "triggers" refers to the method of embedding information in the document that tells the javascript where to attach its event handlers.

Its a misnomer if you are an actual Programmer; they are in fact what we might refer to as "hooks"; the "trigger" would be the event that causes the javascript function to be called (which we would refer to ass the event firing the trigger...)

I think its one of those situations you get where Design and Programming clash, and group 1 uses a term that group 2 has assigned a specific meaning to, not realising that group 2 will misinterpret based on their specific subject domain meaning. You'd probably see the same thing in reverse if I started refering to the bottom of anything in general as a baseline :)


I do fail to see why the server side validation would be parsing the xhtml document served to the client side to get its instructions for validation. Far more likely is that it would use the instructions it used to BUILD that xhtml document in the first place! 

(you know, from where it knew which classes or invented attributes to add to the xhtml elements...)
]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Dante</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P90/#90</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#90</guid>         
	  
      <description><![CDATA[How can anyone think 'class="maxlength=300"' is even close to being semantically correct? 
What you could do if you don't want the bother of the DTD is do something like
&lt;!--MAXLENGTH=300--&gt;
Before the textarea, then use this:
var el = document.getElementById("textareaId").previousSibling;
var maxlength = el.nodeValue.susbtr(el.indexOf('=')+1);

Which is easier? You decide.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Patrick Gotthardt</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P90/#91</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#91</guid>         
	  
      <description><![CDATA[Hi,
First of all: Nice article.

So, now the critics: Neighter "class" nor "custom attributes" is the easiest way to do this.
An much easier way would be, to put it into your JS-Code. Here is how I would do it:

var validator = new FormValidator("id_of_the_form", FormValidatorOptions.VALIDATE_ON_SUBMIT);
validator.addRule("id_of_textarea", ".&#123;0, 30&#125;");
validator.addRule("id_of_required_textfield", ".+");
// that "addRule"-method might take a ValidatorRule-obejct or something similiar instead of the two strings, but it should be clear what I mean.

Isn't that a lot simpler and cleaner? As a plus this javascript could modify the view of the elements to a proper one (e.g. change the class to one showing the result being not valid it if it isn't valid yet).

Someone mentioned MVC previously... I would more like to say it this way:
XHTML is the model. It get's modified and contains the data. It can't be anything else.
CSS is the view. Nothing else, just the view.
ECMAScript is the controller. It is able to modify the data (XHTML) and the view (CSS).

So, having that said, does a modell know what kind of data it is supposed to contain? I don't think so. It just trusts on the controller that prevents bad content from being inserted.
(That's just a note on why I think that my way is correct)


Anyway, I'm not a professional designer or something like that, so I might have just said stupid things. Sorry if I did so.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: R Cotton</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P90/#92</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#92</guid>         
	  
      <description><![CDATA["So, having that said, does a modell know what kind of data it is supposed to contain? I don't think so. It just trusts on the controller that prevents bad content from being inserted.
(That's just a note on why I think that my way is correct)"

This is wrong in the case of XML.

If we were talking about an unstructured text document or a simple array, you would be right; it would not know what was in it.

But XML (and its sibling XHTML) have a TON of information in them about what the data is.

Consider this fragment:

&lt;h3&gt;This is a heading&lt;/h3&gt;

The DATA in that fragment is "This is a heading", the "&lt;h3&gt;&lt;/h3&gt;" pairing is information that describes what kind of data that is; its a heading. Because the xhtml has as its job to hold the data and the typing/structure information to go with it, it most certainly DOES have as its job holding the data, and knowing what the data is.

Rewriting much of your xhtml with Javascript is NOT a good idea; it violates the purpose of the xhtml. It is a pain in the ass to maintain self-modifying code in any system, let alone one as useless for debugging as Javascript. And finally; what happens if the JS is disabled??

JS is best restricted to adding "atomic" behaviours to elements; optional behaviours without which your page still works.

The XHTML (and possibly whatever generates it) is the "boss" of the website; without that element you get NOTHING on screen at the client end. Every other element must be treated as an optional add-on; the page mus still WORK without them. This includes CSS, JS, Flash (spit), ActiveX (vomit) and even images...

(so don't think of the JS as the controller of the xhtml, that is BADNESS)]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Patrick Gotthardt</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P90/#93</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#93</guid>         
	  
      <description><![CDATA[Thanks for your reply.

So, looking at your sample with headings, I would like to explain a bit of my point of view.
You're saying, that a h3 is a heading, this is true. It also specifies what has to be in it, but does it prevent you from adding _wrong_ data? It doesn't. You can put a hole paragraph within a heading and XHTML won't tell you that this is wrong (ok, it does from a logical point, but not from a practical).
So, this is valid XHTML:
&lt;h1&gt;My very long, very stupid paragraph used as whatever it might be used. It might also be styled as a paragraph, but that really doesn't matter, doesn't it?&lt;/h1&gt;

However, it is sementically wrong. But XHTML doesn't stop you doing this. And that is, what I meant.

Another point to consider: form-elements aren't the same as other XHTML elements. They allow direct user input.


Also it seems as if you have misunderstood my sample. The code I've shown won't create XHTML or something like that. It would add EventListeners to the structure and might change view properties. Thus I'm perfectly separating structure from behaviour.
This also includes that someone with javascript disabled won't get hurt by it. When it comes to js-disabled user I'm one of those how try to don't hurt those user.
The only purpose of Javascript is, to enhance the feel for those with JS enabled. Not realizing relevant elements with it.

I'm just _modifying_ the structure with it, letting a functional version of it for those without JS.
As an example: I've created a rich text editor for a CMS I've been working on. However, it only appears if the browser is able to work with it. The others get a textarea. So, I'm absolutly familiar with this thing. ;)]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: R Cotton</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P90/#94</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#94</guid>         
	  
      <description><![CDATA["&lt;h1&gt;My very long, very stupid paragraph used as whatever it might be used. It might also be styled as a paragraph, but that really doesn't matter, doesn't it?&lt;/h1&gt;"

But that is STILL a heading; the fact you've re-styled it to LOOK like a paragraph, and that you personally have decided the length makes it a "paragraph" in your mind, does not change the fact that it is IN FACT a heading... 

Recall, again, CSS may not be in effect, in which case it will render as a HEADING because the xhtml DOES carry structure information! 

And in the absence of anything better, that structure information will be used as presentation instructions; which means you must not go around redefining it on a whim!

]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: R Cotton</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P90/#95</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#95</guid>         
	  
      <description><![CDATA[Patrick, I seriously think you are confusing "what xml/xhtml supports/does" with "what a buggy/non-strict parser (browser) will let you get away with"

You should form you mental abstractions of how things work based on the former, not the latter.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Sebastian Redl</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P90/#96</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#96</guid>         
	  
      <description><![CDATA[Nice article.

First, Patrick Gotthard, you are making a simple mistake here. You are saying that XHTML doesn't enforce the semantics of its content, even though it defines it. This is absolutely correct. You said:
&gt; So, having that said, does a modell know what
&gt; kind of data it is supposed to contain? I
&gt; don't think so. It just trusts on the
&gt; controller that prevents bad content from
&gt; being inserted.
Well, in the case of XML dialects, it has already been shown that the model indeed knows what content it is supposed to contain. But, lacking the active capabilities, it cannot enforce this and must rely on the controller to enforce it.
Given this view, it makes perfect sense to put a validate="..." attribute into the XHTML and read it out with JavaScript.

Of course, in an ideal world we'd all be using XHTML 2.0 by now, where the Schema explicitely allows foreign attributes. Then we could just define them in a different namespace (if you're using any version of XHTML, you should do that anyway) and not mess with custom DTDs, which, among other things, mess up the validator's automatic charset detection.

That said, there are some things in the article I disagree with. Mainly the thing about the class attribute:
&gt; However, the class attribute’s proper use is
&gt; defining CSS triggers.
This is incorrect. The HTML standard says about class:
---
The class attribute has several roles in HTML:

    * As a style sheet selector (when an author wishes to assign style information to a set of elements).
    * For general purpose processing by user agents.
---
This "general purpose" processing very well includes behavioural hooks.

But I do agree that class is not the right thing for everything. class="required" is all right (and you might want to style required elements differently anyway). class="maxlength:300" is not. class sorts elements into groups. That's all it should do.

One more thing about events. I've developed a fairly complete group of functions that can be used to bind stuff to events. It supports the EventHandler functionality even for IE, meaning that you can bind an object that implements handleEvent (or whatever it's called) to an event instead of a function. This has big advantages if you want to carry information.
I'll post it soon on my website.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Patrick Gotthardt</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P90/#97</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#97</guid>         
	  
      <description><![CDATA[... all websites I made so far are valid XHTML 1.1 (no, thanks to IE I'm not sending the right content-type - lukily it is still only a "should be"- and not a "must be"-thing...).
So, I'm familiar with webdesign. It's not required (or of any use) to explain the use of XHTML/CSS to me. Of course my work cannot be compared to what you guys do, but I'm pretty sure that I know what I'm doing. You won't see me using any not required element or anything not standard.

&gt; Given this view, it makes perfect sense to put a validate="..." attribute into the XHTML and read it out with JavaScript.

If this would be possible - yes. But it isn't (you said it will be when XHTML 2.0 is supported? Sounds good - it's sad that this won't be supported for a long time... at least from IE).
If you roll up with your own dialect of XHTML you're not using a standard (and this is the case when you create your own DTD). So, the result isn't a valid XHTML-page. Using what I suggested, the page would be absolutly valid XHTML and could contain this kind of additional functionality.

If you take a look at what this article is about ("triggers" - or I would like to name them "Jump-In points" - for Javascripts) and then think about the solution the article has (create your own DTD and put a lot of your own self-made attributes in your side), then take also a look at where this would end.
My suggestion: There would be people create an attribute for everything where they could need it.
Just take a look at his first sample (the menu). Where would we end when we define an attribute for how the items are supposed to _behave_?
We would end up with the same thing you've had (no, I haven't had this time - I started somewhere in 2002 with webdesign - and I'm happy about this) some years ago, using something that could be rendered on some ways by some browsers, but that wasn't a standard.
This time you add an attribute for form-validation, the next time you add an element for something!

What I want to say is quite simple, but maybe my english is so bad, that you're misunderstanding me...
I will try to repeat it:
Keep behaviour in the behaviour-part and don't put instructions on how something is supposed to _behave_ in the structure. From my point of view, the "class"- and "id"-attributes are structural as well. They help to identify the content of their elements (if they have good names). So, a link with a class "external" will not have that class because of instructions for the view, but for the structure.
But things like form-validation / input-control (do you see that "control"? ;) ) are not part of the structure.
And that is, what I wanted to say. Nothing else.
An attribute "validate" is (just looking at the word) an instruction. Instructions are not part of a structure, or am I wrong when thinking that a structure itself is static? What does a "mask" say about an element?

So, just to say it again, from my point of view an input-validation is part of the behaviour as instructions for it are. Therefor there is no need to put it into the structure.
And creating a custom DTD when it is not required isn't worth this.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: None of your Business</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P90/#98</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#98</guid>         
	  
      <description><![CDATA[Well, if every Web designer now makes his own "standard" (that means: your own attributes in your own DTD) we are back again in 1996. With the small difference, that today not two browser manufacturers are writing the rules, but thousands of designers.

If you use custom attributes there is no need for a Document Type Declaration or Document Type Definition in today's Web at all. Because you are not following existing standards (like HTML 4.01 or XHTML 1.0), there is not much need for validating to see if you follow those rules.

Of course you might use custom DTDs in XML, but that is nothing that should be served in public on the Web. It might be fine on some XML applications on your intranet. When you want to publish on the Web, you have to follow standards like HTML 4.01, ISO-HTML, or XHTML 1.0. Otherwise we get a mess.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: None of your Business</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P90/#99</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#99</guid>         
	  
      <description><![CDATA[Well, if every Web designer now makes his own "standard" (that means: your own attributes in your own DTD) we are back again in 1996. With the small difference, that today not two browser manufacturers are writing the rules, but thousands of designers.

If you use custom attributes there is no need for a Document Type Declaration or Document Type Definition in today's Web at all. Because you are not following existing standards (like HTML 4.01 or XHTML 1.0), there is not much need for validating to see if you follow those rules.

Of course you might use custom DTDs in XML, but that is nothing that should be served in public on the Web. It might be fine on some XML applications on your intranet. When you want to publish on the Web, you have to follow standards like HTML 4.01, ISO-HTML, or XHTML 1.0. Otherwise we get a mess.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>

    <item>
      <title>Posted by: Average Non&#45;Programmer Idiot</title>
	  
	      <link>http://www.alistapart.com/comments/scripttriggers/P100/#100</link>
      <guid>http://www.alistapart.com/comments/scripttriggers/#100</guid>         
	  
      <description><![CDATA[Respectfully...
It seems absolutely snobbish to me to refer to people as idiots and not "real" programmers because of such minor things as people have pointed out. I happen to spend the majority of my time developing using HTML, CSS, and ECMAScript alongside other developers who program in primarily in JAVA. I constantly hear this pettiness about how I'm not a "real" programmer (even though I do program in C++ and JAVA). Some people seem to think that if you don't speak in the market speak given to you by some certification or didn't graduate with a CS degree that you are somehow less worthy of producing content then some others in the field.

If there's an inconsistency in a term, something a laymen might interpret as the author expected but an "expert" would misinterpret, then do point it out. Or if there's an inaccuracy in the coding or a more efficient way, then do point those out also. It would be great though if the statements came with a little less of a judgemental tone and just a little less bickering happened. Treating each other like idiots isn't going to produce better sites or hone anyone's skills.]]></description>
      <dc:subject></dc:subject>
      <dc:date>2012-01-31T13:00:49+00:00</dc:date>
    </item>


    </channel>
</rss>
