SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Forms: Checkbox

  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Location
    Virginia Beach
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Forms: Checkbox

    I have form that uses checkboxes. The value that is sent if a checkbox is selected is 'yes'.

    This works fine, but now I am trying to get the value to send 'no' for any checkboxes that are not checked. (something changes on the database side of things so this is what they are asking for). I know I could use a yes/no radio button. But I was really hoping to leave the checkboxes because the way the form is presented, it makes much more sense.

    I'm not sure if this is possible on the html side of things, it may involve a php script, but if anybody knows a simple way, please let me know.

    Thanks

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,338
    Mentioned
    465 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by jsantiago44 View Post
    I have form that uses checkboxes. The value that is sent if a checkbox is selected is 'yes'.
    That doesn't sound very descriptive. Wouldn't you have a different value for each checkbox? Otherwise, how do you tel them apart?

    Any checkbox that isn't checked obviously is a NO. It sounds like it would be confusing to get a result back from all check boxes.

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jsantiago44 View Post
    This works fine, but now I am trying to get the value to send 'no' for any checkboxes that are not checked.
    You can't do that. A checkbox input sends its value if checked, but doesn't send anything if unchecked.

    Code HTML4Strict:
    <input type="checkbox" value="yes" name="foo">
    <input type="checkbox" value="37" name="bar">
    The first checkbox, if checked, will send foo=yes in the request.
    The second checkbox, if checked, will send bar=37 in the request.
    Neither of them will be present in the request if unchecked.
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Member
    Join Date
    Feb 2006
    Location
    Virginia Beach
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it. Guess I'll have to switch to radio buttons.

    ralph.m, FYI, here is the form I'm working on and why I had wanted to keep it as checkboxes:

    http://smartbeginningsshr.org
    Last edited by jsantiago44; Oct 28, 2009 at 05:40. Reason: typo

  5. #5
    SitePoint Member
    Join Date
    Feb 2006
    Location
    Virginia Beach
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I found the solution. It's in the PHP where I have to do it.

    http://www.homeandlearn.co.uk/php/php4p11.html


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
  •