Re: Single label for 2 inputs?

Grant Perry <Grant.Perry@qed.qld.gov.au> wrote:

> Out of interest exactly what software turns labels into some kind of
> field focus?

If you mean which browsers support it, IE does at least. Mozilla
should but doesn't seem to at the moment. (See bug 28657.)

If you mean how is it specified that a <label>, when clicked on,
focuses its related field, it's not, currently. A browser sees <label>
has having special built-in behaviour; how it implements that
behaviour is up to the browser author.

There is some movement to abstract the behavioural properties of HTML
in the CSS3 'advanced UI' effort, though I don't know if <label> has
been tackled yet. (Personally I believe hiding behavioural properties
in stylesheets is a dangerous mistake, but there are other strategies
the group might use, perhaps.)

> Client Side Scripting [...] is the root of all evil.

It should be possible to define behaviours at the language level
without requiring the user to have scripting turned on for the
current page (with all the dangers that implies). A browser could
define a hook that added onclick event listeners to all new <label>
elements as part of some default scripting of HTML, without allowing
the page author to specify more scripting. Example implementation:

  function labelClickHandler(e) {
    var f= e.currentTarget.getAttribute('for');
    if (f) {
      var inp= document.getElementById(f);
      if (inp && inp.focus) {
        inp.focus();
    } }
  }
  function bind(el) {
    el.addEventListener('activate', labelClickHandler);
  }
  document.addBindingSelector('label', bind);  /* made up example */

> I find it very hard to justify using it consider the lack or
> difference of support browsers have

There is no reason not to use <label>. It adds functionality to a
document without any drawbacks for browsers that do not understand it.

-- 
Andrew Clover
mailto:and@doxdesk.com
http://and.doxdesk.com/

Received on Tuesday, 30 April 2002 08:16:21 UTC