View Full Version : SELECTED in xhtml ?
firepages
09-20-2003, 09:07 AM
Hi, I am parsing (x)html forms and running into problems when an option in a select is SELECTED , and the same with CHECKED for checkboes etc.
whats the compliant way to ...
<option SELECTED value="blah">blah<option>
&&
<input type="checkbox" name="cb" value="cb" CHECKED />
??
liorean
09-20-2003, 02:35 PM
Well, selected="selected" and checked="checked" is your answer.
See <http://www.w3.org/TR/xhtml1/#h-4.5>.
The related DTD sequences (XHTML1.0 Strict, only related lines):
<!ATTLIST script
defer (defer) #IMPLIED
>
<!ATTLIST object
declare (declare) #IMPLIED
>
<!ATTLIST img
ismap (ismap) #IMPLIED
>
<!ATTLIST area
nohref (nohref) #IMPLIED
>
<!ATTLIST input
checked (checked) #IMPLIED
disabled (disabled) #IMPLIED
readonly (readonly) #IMPLIED
>
<!ATTLIST select
multiple (multiple) #IMPLIED
disabled (disabled) #IMPLIED
>
<!ATTLIST optgroup
disabled (disabled) #IMPLIED
>
<!ATTLIST option
selected (selected) #IMPLIED
disabled (disabled) #IMPLIED
>
<!ATTLIST textarea
disabled (disabled) #IMPLIED
readonly (readonly) #IMPLIED
>
<!ATTLIST button
disabled (disabled) #IMPLIED
>
MotherNatrsSon
09-20-2003, 07:46 PM
You cannot use name="blah" it has to be id="blah" to validate.
MNS
liorean
09-20-2003, 08:48 PM
MNS: Wrong. The id attribute is made for uniquely identifying elements in the document, and thus should be used instead of the name attribute on img elements, a elements, form elements, object elements and map elements. However, for form controls, the purpose of name attribute is different. Here, the name attribute is connected with the response sent to the server. Thus, the name attribute is allowed on select, textarea and button elements and even required on input elements, except for the ones where the type attribute is set to 'reset' or 'submit'. (Yes, that means it's required on 'button' and 'image' types for some reason.)
MotherNatrsSon
09-20-2003, 09:46 PM
I was confused by the fact that name is no longer valid for <form> or others. Exceptions to the rules I guess.
My bad :rolleyes:
MNS
liorean
09-20-2003, 11:54 PM
One of the reasons they changed over to id from name, is just to distinguish the unique element identifier from the form control identifier. If it wasn't for the need for a mechanism of having multiple form controls with the same name (for radio boxes and checkboxes) they could have used the same attribute for both. (And there's a difference in what characters are allowed in a name attribute versus an id attribute.)
firepages
09-21-2003, 04:44 AM
lmao , whilst waiting for a reply (cos I hate searching the w3 site) I used selected="selected" so my parser would not break during testing :)
dont even have to 'fix' it now so there could not have been a better answer for me :D cheers !!
whilst I am here :) , is there a downloadable help file or resource that anyone knows of for all these attributes etc ? , I have been on the w3 site but always seem to spend ages there trying to pin down what I am looking for.
and whilst I am still here :)
<td width="300" height="100" align="left">
inline would be ...
<td style="width:300;height:100;???">
how do I specify the align atribute ? , in my css lists I can see valign but not align , they obviously called it something different to confuse me ;)
MotherNatrsSon
09-21-2003, 07:28 AM
It is either vertical-align or text-align depending on what you want to align.
CSS 2 Reference (http://www.w3schools.com/css/css_reference.asp)
vetical-align
Sets the vertical alignment of an element baseline
sub
super
top
text-top
middle
bottom
text-bottom
length
%
MNS
text-align
Aligns the text in an element
left
right
center
justify
firepages
09-21-2003, 08:04 AM
DOH ! :D
I use text-align:justify all the time so why I did not realise ??
Cheers !
liorean
09-21-2003, 09:30 AM
Hmm I know of no great resource, but I always keep a copy of the xhtml dtds handy.
liorean
09-21-2003, 09:31 AM
Hmmm, you can't put multiple attachments in one post...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.