Could someone help me get a better understanding of what this code really says...
<th class='colSelect' />
<input name='selectAll' type='checkbox' value='TRUE' />
I think it means that IF the Checkbox is checked, and IF it is submitted on a Form, THEN it will have a value of "TRUE", which for example, might be what is stored in the database?
(When I first read this last night - for some old code I forgot about - I thought it was saying, "This Checkbox is pre-selected/pre-checked with a value of 'TRUE'..." which is not what I want?!)
I thought it was saying, "This Checkbox is pre-selected/pre-checked
In order to have that, the code you posted would also need to have
Okay, but you missed the main question which is trying to understand what value='TRUE' means and does...
The VALUE attribute, required for radio buttons and checkboxes, unsurprisingly gives the value (chosen by the author) of the control when it is checked. The boolean CHECKED attribute specifies that the control is initially checked.
Each checkbox stands for something—an option—and you place something in the value attribute to indicate what that option is (for the sake of PHP). So when you get the results of the form, you'll know which option was chosen via the value that is returned. Presumably there would also be a label of "True" associated with this input, or something similar, for the sake of the user, as in:
The end is nigh!
So I had it right in my original post.
When this form is submitted, selectAll="TRUE". Do note this is the STRING "TRUE" and not a boolean TRUE ( tho the string will eval to TRUE).
For example if the value was "FALSE" selectAll="FALSE", but since it's the STRING "false" and not the boolean FALSE, it too will eval as TRUE!!!
for this reason its best to use a 1 (true) or a 0 (false) in this kind of situation.
Yes, value is optional except when the type attribute has the value "radio" or "checkbox".
There's also an error in the way the input is NOT wrapped inside a <th> tag. If the <th/> preceding it is self closing and you are serving the page as XHTML then the page should not display because there is no opening tag to correspond to the </th> following the input. If served as HTML then the / is invalid anyway - but will be ignored.
While the attribute is optional, it's important the server knows what the client is trying to convey.
Radio buttons and check boxes are included in the submitted request if checked. With checkboxes, as long as their name is unique, there isn't a problem with them having no value as long as the server side code is written to deal with it. 99% of the time that isn't the case - the server side code will check to see if the value is logically true. The default value of any input element is empty string in PHP, which is logically false. So, we have a problem.
Radio buttons without values are worse. In order to get the radio behavior all the radio buttons of a set should share a name. Unless they have different values there's no way to ascertain which one was checked from the server side.
Just because code is valid doesn't mean it will be functional, or even clear to the maintenance programmer that comes after you.
This topic is now closed. New replies are no longer allowed.