PDA

View Full Version : XHTML Strict Forms


Saj
04-08-2003, 12:42 AM
Hi.

While using XHTML forms, a name tag is optional. However, in XHTML Strict, it is not allowed. Does anyone know of another attribute that works the same way in Strict??

Thanks

liorean
04-08-2003, 01:23 AM
It does exist on form elements (though not on actual forms) and on object elements in XHTML strict.

From the XHTML 1.0 Strict DTD (http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd) (row 716-742):

<!ENTITY % InputType
"(text | password | checkbox |
radio | submit | reset |
file | hidden | image | button)"
>

<!-- the name attribute is required for all but submit & reset -->

<!ELEMENT input EMPTY> <!-- form control -->
<!ATTLIST input
%attrs;
%focus;
type %InputType; "text"
name CDATA #IMPLIED
value CDATA #IMPLIED
checked (checked) #IMPLIED
disabled (disabled) #IMPLIED
readonly (readonly) #IMPLIED
size CDATA #IMPLIED
maxlength %Number; #IMPLIED
src %URI; #IMPLIED
alt CDATA #IMPLIED
usemap %URI; #IMPLIED
onselect %Script; #IMPLIED
onchange %Script; #IMPLIED
accept %ContentTypes; #IMPLIED
>


And I really think you should learn to distinguish tags from attributes - there were never a name tag in any version of html.

Saj
04-08-2003, 01:44 AM
Yes, sorry about the mixing of attributes and tags. However, whenever I add the name attribute to the form tag like:

<form name="form1" action="test.html">

It always picks it up as invalid in XHTML Strict on the W3 Validator. With all of the other tags in the form, input tags, I need the id attribute for it to work, but there is nothing like the id for the <form> tag.

Saj
04-08-2003, 01:48 AM
Below are the results of attempting to parse this document with an SGML parser.

Line 46, column 11: there is no attribute "name" (explain...).
<form name="triangle" action="index.html">

liorean
04-08-2003, 02:13 AM
Oh:<!ENTITY % coreattrs
"id ID #IMPLIED
class CDATA #IMPLIED
style %StyleSheet; #IMPLIED
title %Text; #IMPLIED"
>

<!ENTITY % attrs "%coreattrs; %i18n; %events;">

<!ELEMENT form %form.content;> <!-- forms shouldn't be nested -->

<!ATTLIST form
%attrs;
action %URI; #REQUIRED
method (get|post) "get"
enctype %ContentType; "application/x-www-form-urlencoded"
onsubmit %Script; #IMPLIED
onreset %Script; #IMPLIED
accept %ContentTypes; #IMPLIED
accept-charset %Charsets; #IMPLIED
>

See, the form tag has the id attribute, like everything else. Use that for reaching a specific form, or use the numerical index. The form tag doesn't have the name attribute, since it didn't provide anything that the id attribute didn't. Name on form elements (input, button, textarea, select) does provide an interface to groups on named elements instead of individual elements, and because of that is needed. In fact it's required on non-submit/reset form elements.

Saj
04-08-2003, 03:12 AM
I thought that the id attribute would be used, but if I use it, then the script doesn't work at all. Can you take a look at it?

By the way, the name attribute is accepted in XHTML Transitional, but not Strict.

brothercake
04-08-2003, 09:44 AM
You're going like this (for eg):

document.triangle.a.value

which is not a valid way of reaching an element by ID (it's not really a valid way of reaching it by name either, but that's another story)

Try

document.getElementById("triangle").elements["a"].value

Saj
04-08-2003, 01:26 PM
Aha, ok thanks I see now. I didn't even think of that.

Thanks.