Roll Your Own Elements and Attributes
We use Microsoft Internet Explorer’s XML element in both IE and Firefox. The interesting thing is that, unlike Internet Explorer, Firefox doesn’t support the XML element, so how exactly did it work? According to several recommendations published by the World Wide Web Consortium, when an unrecognized document element is encountered, it needs to be handled gracefully. Most likely, this is a “plan for future expansion” thing.
Think about it; this makes a great deal of sense because if you go without it, boom, the web browser would just roll over and die whenever somebody with sausage fingers mistyped a tag. The World Wide Web wouldn’t be a pretty sight without this feature. Interestingly, the same feature is also available for attributes, which explains how the home-grown data binding works.
A number of times in the past, I took advantage of this in regard to attributes. I took advantage of this little trick in several different ways, but I have a couple of favorites. The first was stashing the original values of HTML input objects for the purposes of resets. Click a button, and a client-side JavaScript event handler would update the value attribute from the oldvalue attribute.
Another one of my favorite uses was to use it as a “value has changed” indicator. This indicator would be checked when the form was submitted. Based upon the result of a test, any number of actions could be taken, including producing a client-side error message.
However, my most favorite was to stash other options for selects. You see, the system that I worked on had pages with several HTML select objects with the contents of each select based upon the selection made in the previous select. Originally, whenever a visitor came to the website and made a selection, that visitor was forced to wait through an unload/reload for each selection.
The “mad scientist” solution was to create a series of attributes consisting of the various attributes. Each select had an onchange event handler that would update the options of the next logical select object. Although this wasn’t an Ajax application, the change that I made gave it one of the same characteristics; it didn’t bother the server any more than absolutely necessary.
Comments
Leave a Reply
You must be logged in to post a comment.
