doubledee — 2012-12-08T11:54:12-05:00 — #1
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?!)
stomme_poes — 2012-12-08T13:11:56-05:00 — #2
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
doubledee — 2012-12-08T14:34:59-05:00 — #3
Okay, but you missed the main question which is trying to understand what value='TRUE' means and does...
xhtmlcoder — 2012-12-08T15:01:25-05:00 — #4
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.
ralphm — 2012-12-08T18:12:22-05:00 — #5
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!
doubledee — 2012-12-08T18:34:57-05:00 — #6
So I had it right in my original post.
zcorpan — 2012-12-10T10:57:05-05:00 — #7
dresden_phoenix — 2012-12-10T11:35:44-05:00 — #8
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.
xhtmlcoder — 2012-12-10T12:43:22-05:00 — #9
Yes, value is optional except when the type attribute has the value "radio" or "checkbox".
felgall — 2012-12-10T13:34:14-05:00 — #10
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.
zcorpan — 2012-12-18T10:39:24-05:00 — #11
xhtmlcoder — 2012-12-18T11:04:43-05:00 — #12
zcorpan — 2013-02-18T07:15:44-05:00 — #13
michael_morris1 — 2013-02-18T09:20:48-05:00 — #14
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.