SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,529
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Value=TRUE for Checkbox

    Could someone help me get a better understanding of what this code really says...
    HTML Code:
    	<th class='colSelect' />
    		<input name='selectAll' type='checkbox' value='TRUE' />
    	</th>

    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?!)

    Comments?

    Thanks,



    Debbie

  2. #2
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,233
    Mentioned
    47 Post(s)
    Tagged
    1 Thread(s)
    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
    checked
    or
    checked="checked"

    to mean pre-selected. The "checked" attribute when hand-coded into the HTML is considered part of the "default" values of the form (what you would have if you made changes to the form, but then hit a input type="reset" button... also Javascript, or at least many JS libraries, make a distinction between default checked/unchecked states and states set by the user).

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,529
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    In order to have that, the code you posted would also need to have
    checked
    or
    checked="checked"

    to mean pre-selected. The "checked" attribute when hand-coded into the HTML is considered part of the "default" values of the form (what you would have if you made changes to the form, but then hit a input type="reset" button... also Javascript, or at least many JS libraries, make a distinction between default checked/unchecked states and states set by the user).
    Okay, but you missed the main question which is trying to understand what value='TRUE' means and does...


    Debbie

  4. #4
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,594
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    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!
    - True
    - False

  6. #6
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,529
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    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!
    - True
    - False
    So I had it right in my original post.

    Thanks,


    Debbie

  7. #7
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by xhtmlcoder View Post
    The VALUE attribute, required for radio buttons and checkboxes,
    s/required/optional/
    Simon Pieters

  8. #8
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,731
    Mentioned
    31 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    Yes, value is optional except when the type attribute has the value "radio" or "checkbox".

  10. #10
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,600
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    Could someone help me get a better understanding of what this code really says...
    HTML Code:
    	<th class='colSelect' />
    		<input name='selectAll' type='checkbox' value='TRUE' />
    	</th>
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  11. #11
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by xhtmlcoder View Post
    Yes, value is optional except when the type attribute has the value "radio" or "checkbox".
    [citation needed]
    Simon Pieters

  12. #12
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)

  13. #13
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by xhtmlcoder View Post
    Thanks.

    The value attribute is always optional in the current HTML spec. Radio buttons and checkboxes have the default value "on". http://www.whatwg.org/specs/web-apps...lue-default-on
    Simon Pieters

  14. #14
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,011
    Mentioned
    56 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •