tags:

views:

147

answers:

3

Is the following allowed?

<input type="hidden" name="field" />
+8  A: 

It is fine in hidden fields. It is only required in checkbox and radio inputs. It can never be specified with a file input. See http://www.w3schools.com/TAGS/att_input_value.asp

carl
Definitive link: http://www.w3.org/TR/html4/interact/forms.html#adef-value-INPUT, even though as Assaf says the HTML DTD/Schema does not enforce the radio/checkbox limitation. In practice of course browsers default the value to ‘on’ for these.
bobince
+2  A: 

Yeah, form inputs are under your control to serve your requirements, so long as they're well-formed and valid xhtml.

It does seem a touch pointless though.

David Thomas
Saving transfer :P Although small, in this case, each call with will be missing 20 value="" and this call could be made 1000s of times for one user. The saving might be small, but makes the code a little cleaner...although less obvious.
Darryl Hein
Ah, well thought out, that man! :)
David Thomas
+5  A: 

XHTML 1.1 schema says that value is not mandatory:

 <xs:attributeGroup name="xhtml.input.attlist">
    <xs:attributeGroup ref="xhtml.Common.attrib"/>
    <xs:attribute name="type" type="xhtml.InputType.class" default="text"/>    
    <xs:attribute name="name" type="xh11d:CDATA"/>
    <xs:attribute name="value" type="xh11d:CDATA"/>
    <xs:attribute name="checked">
      <xs:simpleType>
        <xs:restriction base="xs:NMTOKEN">
          <xs:enumeration value="checked"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="size" type="xh11d:Number"/>
    <xs:attribute name="maxlength" type="xh11d:Number"/>
    <xs:attribute name="src" type="xh11d:URI"/>
    <xs:attribute name="tabindex" type="xh11d:Number"/>    
    <xs:attribute name="accesskey" type="xh11d:Character"/>
  </xs:attributeGroup>
Assaf Lavie
Question has the tag "html", which is different from xhtml 1.1. Pedantry I realize, but anyone who is actively using xhtml 1.1 should be well-versed in said pedantry.
Tom
Question also has the <input> as <input/>, so clearly non-valid HTML but rather XML ...
Joey
@Tom, I'm the one who added the html tag...
Assaf Lavie