Slashdot Mirror


Check Boxes and Radio Buttons Conquered by DHTML

Philip Howard writes "Pretty much every form element has been conquered by CSS so far, letting us create stylish, integrated forms to tie in closely with our site designs for that UI polish graphics artists love to have. Radio Buttons and Check Boxes, however, have resisted most attempts to style them consistently, accessibly and elegantly- perhaps because nobody cares enough to come up with the solution. However, these elusive form elements have finally been conquered with a simple combination of CSS and Javascript and a little HTML wrapper. The solution is easy and quick to implement, is accessible (working with tab and space) and elegantly degrades where CSS and/or XHTML is not available."

23 of 522 comments (clear)

  1. Not really new, but interesting by AKAImBatman · · Score: 5, Informative
    In reading TFA, it seems that the author hasn't done anything actually new. He's just inserting styled DIV tags with click handlers attached to them. His primary concern (and what he believes he's invented) is a method to be backward compatible with browers that have JavaScript turned off, and/or browsers that lack CSS support. (You actually want to support those guys?)

    His solution is very similar to what mine would be. I'd just walk the DOM looking for checkboxes, then replace them with some inline element creation code. His solution is to get a list of all links, then find any with a special class. He then goes on to replace the contents of the links via the innerHTML property. Clunky, but it does work.

    To the author: You can achieve your goal much more easily by attaching the className to the checkbox directly. Use getElementsByTagName to get a list of INPUT tags, then loop through those. When you find one you want to replace, use the
    document.createElement()
    function to build the replacement tag on the fly. You can then use
    checkbox.parent.replaceChild(newCheckbox, checkbox)
    to swap out the tags in a hurry.

    Oh, and using an anchor tag for event handling is very 1990's. Try doing something like this instead:
    newCheckbox.onclick = function(e) {
    toggleCheckbox(newCheckbox, '', 'StyledCheckbox'+checkboxIndex+')
    };
    Note that you don't actually need the "StyledCheckbox" name, because you would be passing the actual element through to the event handler.

    Good luck on your work. :-)
    1. Re:Not really new, but interesting by hacker · · Score: 5, Informative
      "His primary concern (and what he believes he's invented) is a method to be backward compatible with browers that have JavaScript turned off, and/or browsers that lack CSS support. (You actually want to support those guys?)"

      Yes, you most certainly do.

      • Cellphones, pagers, "always-on" mobile Internet devices
      • PDAs and handhelds, handheld browsers
      • Devices for the blind, text-to-speech readers
      • WAP devices
      • Screen scrapers
      • RSS syndication

      If CSS delivers the style, and the HTML still delivers the content, then those will continue to work.

      Once you start using Javascript or CSS to deliver the CONTENT, then you're doing something wrong, and breaking lots of your visitors.

      Many Flash developers don't seem to understand this either (modulo the huge list of problems with using Flash). HTML should deliver the Flash, not the reverse.

    2. Re:Not really new, but interesting by thirteenVA · · Score: 4, Insightful

      Here we go...

      Why is it that amongst web developers there is only considered to be 'one way to do things'.

      Standards compliance is a good guideline, but it is not law.

      Web developers only need to cater to those devices in which they expect their content to be viewed. I do not expect, nor do I desire for someone to use my company's web apps from a cellphone or PDA.

      Yet, people wear their xhtml compliant gif's like medals of honor.

      Write your pages with compliance in mind, but never lose site of refining your apps and pages for your target audience, regardless of it if bends the standards.

    3. Re:Not really new, but interesting by gstoddart · · Score: 4, Insightful
      Many Flash developers don't seem to understand this either (modulo the huge list of problems with using Flash). HTML should deliver the Flash, not the reverse.

      This is my biggest problem with flash.

      There is nothing more annoying than browsing to a site from a machine which doesn't have flash installed (don't want it) and realizing the site was written in such a way as to not be able to get past the into animation without flash.

      People who make web-sites which can't be operated without flash need beatings.
      --
      Lost at C:>. Found at C.
    4. Re:Not really new, but interesting by MarkEst1973 · · Score: 4, Interesting
      Is anyone really browsing the web from their cell phone? PDA? The resolution and functionality in these things are terrible. We have a decade of hard experience behind us building good web browsers. Let's build one into devices that want to surf the web.

      The same goes for screenreaders. I have to make my applications Section 508 compliant everyday because we're a gov't contractor. It sucks. If Mozilla and IE know what elem.innerHTML is and can render it, why can a screenreader not work like a real goddamned web browser? Then it too would know what my elem.innerHTML is and can read it accordingly aloud to the non-sighted user.

      There are real 508 problems for blind folks. Implementing a "skip nav" hidden link to bypass the multitude of primary navigation links is standard. If we can pass the user around the page like that, why not include more dynamic pieces in the page and present a non-visible menu for blind people? "Press 1 for My Profile, Press 1 for ... blah blah blah". As they press a button, *javascript and dhtml* take them around the page, reading more parts of the menu.

      In my mind, a very accessible app would be more like a phone VRU to a blind person. But what's the problem? JAWS doesn't know shit about a page beyond html markup. It was only in the past few years that they managed to handle nested tables well. So blind people are lost when it comes to even Section 508 compliant websites, because screenreaders as they exist today suck.

      Rich web applications (a la GMail, Google Maps, Flikr, Backpack, and other AJAX style applications) are a rennaissance of web programming. They are increasing usability at the expense of accessibility. The vast majority of users are sighted and on a PC. I don't think the solution is to code down to the lowest common denominator, but to build up the other dumber clients of web apps.

    5. Re:Not really new, but interesting by hacker · · Score: 5, Insightful
      "There is nothing more annoying than browsing to a site from a machine which doesn't have flash installed (don't want it) and realizing the site was written in such a way as to not be able to get past the into animation without flash."

      I'll give you some more fuel to pour on that fire:

      1. Can't change contrast (for those who might be colorblind and can't see light grey text on a white background. Who taught these kids color theory anyway? Barney the dinosaur?)
      2. Can't change font size (whaddya mean you can't see my 6 point fonts, what are you, blind?)
      3. No ability to search the text of a flash page using standard browser "Find" functions (yes, some search engines can index Flash now, with the proper hooks into the Macromedia Flash SDK, but its not exposed on the user end)
      4. No fallback for non-Flash browsers, built into the Flash itself

      It irritates me too, so I just don't use it, or recommend sites that do. Let's just make our entire site in PostScript, or better yet an OpenOffice.org .sxw or an OpenDocument .odp file format.

      "Why not? You don't have the right plugin? Oh, too bad... get with the times!"
      </sarcasm>
      "People who make web-sites which can't be operated without flash need beatings."

      People just need beatings anyway, just to let them know they can be beaten by anyone for any reason. This whole "Gimme" generation and the new business model of "Don't have a viable business plan? Sue someone! Profit!" needs to stop.

      I'm going to have to start a new campaign called "Slap the Stupid out of Everyone" that does just that. Can't count change in the drive-thru? Find a new job, you're fired. Can't figure out how to answer questions about your product in the store? You're fired. Parking like an idiot? Towed.

      I'm tired of just ignoring and tolerating stupidity and ineptitude and excuses. It has to stop.

    6. Re:Not really new, but interesting by Shaper_pmp · · Score: 5, Informative

      "Why is it that amongst web developers there is only considered to be 'one way to do things'."

      My theory is that it's a combination of:

      1. More complex up-front design considerations than many other development tasks - your code is written once, but should run perfectly (or degrade gracefully) on every browser for every operating system for every architecture it ever runs on. In the website design community we deal every day with headaches caused by bugged or incompatible-by-design APIs, sketchy standards support and incredibly customisable interfaces (what's the C/C++/Java equivalent of "disable stylesheets", eh?). When you find a technique that works perfectly/degrades well on all known implementations, you stick to it like glue, and disseminate the word so others don't have to rip their own hair out. CSS tricks are even more slavishly followed, because so many rely on precise, back-engineered quirks of different browsers' rendering algorithms.

      2. A large segment of much less-educated community participants. A lot of web designers (even now) have come at it from a graphic design background, and fail to appreciate the complex requirements and difficulties inherent in javascript, XHTML, CSS and how they all interact. Solving a lot of common problems with one approach which can be copied by the less-knowledgeable is a big win when it stops people re-inventing the wheel (and making it square - Flash developers, I'm looking at you).

      3. Look where pandering to IE/Netscape and coding to browser quirks got us in the 90s - sometimes it took longer to make a site work acceptably in all browsers than it did to design and implement the first complete version! Quite often these days you'll find the "one way to do it" is basically conforming to the standards, avoiding proprietary extensions and writing pages which validate. There's nothing wrong with it, it encourages browser-manufacturers to conform to the standards, it simplifies the job of the web designer/developer and it doesn't restrict creativity one jot.

      "Standards compliance is a good guideline, but it is not law."

      No, but it is the only thing that stops you unnecessarily spending twice as long on a job coding to browser quirks. And it does ensure that everyone will be able to at least see the information, even if it's not necessarily pretty (pretty is easy too, for a further small investment of time). And it does mean you can tell the difference between a skilled, professional webmaster and someone's kid nephew with a copy of Frontpage.

      "Web developers only need to cater to those devices in which they expect their content to be viewed. I do not expect, nor do I desire for someone to use my company's web apps from a cellphone or PDA."

      Then, with apologies, you fail to understand the fundamental nature of the web. The whole point of the web is that anyone should be able to access information (and web apps count as information), however they like.

      "Not expecting" customers to use different browsers only shows that you're closed-minded or not very imaginative (especially for someone posting on Slashdot!). "I didn't expect it" is a pathetic justification when something doesn't work unnecessarily, and indicates a lack of professionalism in your execution.

      "Not desiring" it (eg, coding to a specific browser as my company does - I don't) means you're effectively locking yourself and your customers into one company, and everyone knows vendor lockin is a pointless risk - even Microsoft's now paying lip-service to interoperability.

      "Yet, people wear their xhtml compliant gif's like medals of honor."

      Yes. They're proudly saying "Look - I'm a professional". Or "I care about doing things The Right Way". Or even "Fuck off browser-makers, unless you can make it work according to the standards". How are these a bad thing?

      "Write your pages with compliance in mind, but never lose site of refining your apps and pages for your tar

      --
      Everything in moderation, including moderation itself
    7. Re:Not really new, but interesting by poot_rootbeer · · Score: 4, Informative

      I do not expect, nor do I desire for someone to use my company's web apps from a cellphone or PDA.

      I, as a user, expect the web apps I use to be usable from any web browser available to me, including cellphones and PDAs.

      If your company will not provide this ability to me, I will visit your competitors and see if they will.

    8. Re:Not really new, but interesting by Pete · · Score: 4, Interesting
      Well, I am actually coding it to be standards-compliant. And it is. It just doesn't YET work correctly in KHTML/KJS or Opera (believe it or not, neither of those engines are perfect - of course, neither is Gecko/Spidermonkey, but G/S is less imperfect :-)). But they're getting closer - it seems that every time I test a new Konq or Opera release, more things work correctly.

      This is not your usual web application. It's all a single page, and almost every user action is handled with asynchronous XMLHttpRequests. It's pushing the envelope a fair bit, yes - but my boss is happy and so I'm happy too :). It is pretty amazing what you can do with Ajax when you don't have to be held back by IE limitations.

      What if your employer opens the site up to a new partner, which only uses MSIE? What now?

      Well, it's pretty damn simple. If they want to use the app, they use a supported environment *shrug*. Just like any other software vendor. Except it's about a billion times easier to install and run an alternative browser than it is to install and use an alternative operating system on your computer (when my boss was demonstrating to a potential client, it took him all of two minutes to (a) download, install and run Firefox and (b) get our app running on the newly-installed Firefox).

      In some ways it's easier if you think of it like the web application is a "real" application. It's just that you install Firefox (or Mozilla, or K-Meleon) on your desktop to "run" the application (instead of, eg. a Java or .NET runtime environment). And of course in the near future our app will work with every major browser except IE.

    9. Re:Not really new, but interesting by mcfuddlerucker · · Score: 4, Insightful

      >> the guy who wrote it is either lazy, unprofessional, working to an unrealistic schedule or shit at his job.

      Thankfully you put that middle one in there. I was about to cloud up and rain all over your ass.

      Many of us want to do, and vocalize the importance of doing the right thing, but our hands are tied. Don't forget that.

    10. Re:Not really new, but interesting by pocopoco · · Score: 4, Informative

      >Yes, I'm a purist like that.

      Anyone else find it amusing that these "purist" people haven't even read the official specification? It's clearly stated at http://www.w3.org/TR/xhtml1/ that you are allowed to send XHTML 1.0 (which is what most sites are using) as text/html and they even give you an appendix full of compatibility tips when doing so.

  2. The real question is by Rosco+P.+Coltrane · · Score: 5, Funny

    Will Lynx render them correctly with ascii-art?

    --
    "A door is what a dog is perpetually on the wrong side of" - Ogden Nash
    1. Re:The real question is by AKAImBatman · · Score: 4, Insightful

      Will Lynx render them correctly with ascii-art?

      Yes, actually. While I'm none to keen on the idea of supporting old browsers in DHTML/AJAX/Whatever-you-want-to-call-it-this-week applications, his solution is designed to allow for normal checkboxes to show in browsers that lack JavaScript. As a result, the normal "text" checkboxes would show in Lynx. At least until Lynx gets full JavaScript and DOM support. Then you have problems. ;-)

  3. Check Boxes and Radio Buttons Respond: by Anonymous Coward · · Score: 5, Funny

    This occupation won't stand! You may think you can apply your western styles upon us by force, but history will prove you wrong.

  4. Is this a good thing? by AtariAmarok · · Score: 4, Interesting

    Is it a good thing to have controls that deviate from the standard so much that they aren't even recognizable anyore, like the green/grey round toggle button that replaces the checkbox on the sample page? Why disguise standard controls so the user will have to spend some time trying to find out what the standard controls are "hidden as"?

    --
    Don't blame Durga. I voted for Centauri.
  5. Damn you, Slashdot. by bigtallmofo · · Score: 4, Funny

    I just hope the marketing people that work in my company aren't reading Slashdot today.

    Otherwise, I'll be making fancy checkboxes for the next 2 months.

    Damn you, Slashdot.

    --
    I'm a big tall mofo.
  6. Spiffy by generic-man · · Score: 5, Interesting

    The examples look very nice. I still think the bigger problem is that web applications have absolutely no UI consistency between them, though. On one web site, select-boxes cause a form to be immediately submitted when a selection is made; on others, you have to click "Go." On one web site, check boxes look like boxes with check marks; on another they look like stars; on another they look like glowing orbs (not very colorblind-friendly).

    This is the sort of thinking that leads to such UI atrocities as Winamp, iTunes for Windows, and Firefox for Mac OS X: all three of these ignore most of the native widget drawing capability in the name of creating a pointlessly slick, cross-OS-consistent experience.

    I for one welcome the arrival of XAML and XUL: ways to describe forms that every OS will render using its own navigation and widget capabilities. It'll be as awesome as the time Java solved that problem for everyone everywhere.

    --
    For more information, click here.
  7. are they really blinky for anyone else? by pezpunk · · Score: 4, Informative

    granted i'm not exactly running the latest hardware, but every click on a radio button seemed to illicit a lot of blinking and flashing on the part of the other buttons. maybe it's just javascript running slowly as the DIVs move around or something, but i prefer to think of it as simple jealous from the other buttons in that group. "click me instead!" "no me!"

    in any case, i'm all for flashy design, but this seems to be more trouble and more cumbersome than it's worth, unless that javascript can be optimized to not be so slow.

    --
    i could live a little longer in this prison
  8. On bells and whistles by PIPBoy3000 · · Score: 4, Insightful

    There are certainly some people out there who are impressed by cool graphic tricks.

    After writing web applications for ten years, though, I find that more and more people simply want to get the job done. Perhaps it's that I work in Healthcare and my customers are busy people caring for patients.

    The other thing that makes me nervous about bells and whistles is that they add complexity to things. Complicated things break. Browser makers have changed how they implement CSS and DHTML before and there's a good chance they'll change it in the future. Basic support for checkboxes will last another fifty years.

  9. Missing the point by illtron · · Score: 4, Insightful

    A lot of people seem to be missing the bigger point here. It's not that he's replacing checkboxes with images, it's that he's managing to do it while keeping the page properly structured and accessible to all browsers. While the page isn't quite all the best HTML underneath (what's with the tables?), if you look at the forms, it's proper HTML and not some javascript hack that will break old browsers.

    I think that's the point, anyway.

    --
    Slashdot: 24 hours behind every other site or your money back!
  10. Re:Why JavaScript? by mrchaotica · · Score: 4, Insightful
    However, the only times I get to "experience" it are when websites want to do something stupidly useless, like resizing windows or goofing with the mouse pointer, or bury me in multiple cascading popups.
    The corollary of that is that when JavaScript is used correctly, you don't notice it (e.g. Google's various pages).
    --

    "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

  11. Fucking graphic design majors by Thaelon · · Score: 4, Insightful

    One of the most fundamental concepts of good UI/GUI design is that you DON'T INTRODUCE NEW THINGS.

    Everytime you introduce something new the user has to learn how to use it or what the fuck it is. This is bad. Really bad. You just won't believe how vastly, staggeringly, jaw-droppingly bad it is.

    It may seem incredibly anal, stale and anti-progressive but that's the whole point. There's no such thing as an innovative interface because innovation has connotations of something both new and better. In the realm of Human Computer Interaction (HCI) new and better are mutually exclusive. Good UIs are simple, intuitive and introduce absolutely nothing new. Ever.

    There are only two truly intuitive interfaces in existance. The nipple and the vagina. The rest you have to learn how to use.

    Save the styled checkboxes and radio buttons for other people in your yuppie coffee house. Your average user doesn't want them, won't understand them, won't appreciate them and doesn't care what they look like.

    --

    Question everything

    1. Re:Fucking graphic design majors by RosenSama · · Score: 5, Insightful
      I don't agree with this in two different ways.

      #1 "new and better are mutually exclusive"
      You are saying there is no way to improve UI. If new (change) is mutually exclusive with better than then only thing left is old (unchanged). Without change, there's no way to get better leaving a permanent status quo. By adhering to these arguments we'd still have rotary phones, analog clocks, and the command line.

      #2 They didn't introduce a new UI element, they just learned how to make existing ones match the page.