[whatwg] OUTPUT tag: clarify purpose in spec?

Ian Hickson ian at hixie.ch
Mon Dec 2 16:24:27 PST 2013


On Thu, 26 Sep 2013, Jukka K. Korpela wrote:
> 2013-09-26 21:41, Ian Hickson wrote:
> > 
> > There's a lot of <output> examples in the spec; do they help at all?
> 
> There are indeed several examples, but they are scattered around; the 
> section that specifically deals with the <output> element, 4.10.15, has 
> only one example.

I've added a second.


> It is a simple calculator that shows the calculated result in an 
> <output> element. And it is a form with no action attribute and with 
> onsubmit="return false", so it is clearly meant to work in the browser 
> only. That is, the value of the output element is not submitted.

Correct. <output> elements are never submitted, actually. They're not 
submittable.


> The question then arises why <output> is used, instead of just showing 
> the result in a <span> or <div> element as usual.

Indeed. Often the benefit to using a more appropriate element rather than 
just using <span> everywhere is not immediately obvious.

In the particular case of the calculator example, the main benefit is that 
the snippets of script become much simple:

   oninput="o.value = a.valueAsNumber + b.valueAsNumber"

...rather than:

   oninput="document.getElementById('o').textArea = a.valueAsNumber + b.valueAsNumber"


> In fact, none of the examples about <output> have no apparent 
> association with any submission to server-side processing.

Right, <output> doesn't have much to do with submission.


> Yet, the from the properties defined for <output>, whole point seems to 
> be that the <output> element has a special purpose: it is a control, 
> with a value that may be included in form data upon submission

It's a control, but it's not submitted.


> but its value is not meant to be changed by the user directly, only via 
> actions that may indirectly modify it.

Right.


> Simultaneously, it is normally visible to the user.

Right. These various points distinguish it from <input type=hidden>, which 
is hidden and is submitted. The closer cousin would be <input type=text 
disabled>; the main difference between <output> and a disabled text field 
is that <output> renders normally (inline, like a span) rather than being 
in a finite-sized box with no user interaction and grayed out.


> As I see it, the difference between <output> and a readonly <input> is 
> that the latter is not meant to be changed by the user *at all*, whereas 
> <output> is not be changed *directly*.

A read-only input is submitted, also, which is another difference. A 
read-only input text field is also of finite size on the display (you have 
to scroll it to see the whole text), and it is usually implicit in its 
existence as a control rather than an <output> field that in principle the 
data might be editable (e.g. maybe it was editable before the user 
committed to its current value).


> It's of course too late to change the name "output" now, but it is really
> misleading, since it suggests that the element is just for output (possibly
> even suggesting that it's really a duplicate of <samp>!).

The element is just for output, so that seems accurate.

It is distinct from <samp> in that <samp> is more like a quote of another 
process' output. Another way to put it is that, <samp>x</samp> is more 
like <q><output>x</output></q>, semantically.


> Yet it seems that it primarily computed data (in a broad sense for 
> "computed") to be submitted, though it can, like <input>, be used 
> without submission too.

It's primarily for the output of computed data, right.


> So <computed> or <input type=computed> might have been better.

<computed> would have been equally valid, yes. <output> is probably the 
more familar term, though.


> I mention this because this name problem emphasizes the need for 
> explaining what the element is really for.

The output element represents the result of a calculation or user action. 
That's what the spec says. I'm not sure what more you want it to say.


> I still don't quite see *why* <output> has been introduced. I can 
> understand it as a purely logical creation, but what is the practical 
> gain expected to be?

The main practical gain is that it makes outputting data from script in a 
form easier, since <output> is a listed form-associated element.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


More information about the whatwg mailing list