Results 1 to 2 of 2

Thread: Checkboxes - Comma delimited list

  1. #1
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cool Checkboxes - Comma delimited list

    i have a browse page where i have checkboxes to allow members to select different age groups. I got the sort part all working, my problem is the boxes that are checked don't stay checked when the page is relaoded to show the new results.

    here's what i have, i'm so lost ... if anyone can help i'd really appreciate it!

    PHP Code:
    if (isset($HTTP_POST_VARS['agesort']))
        {
    $setage implode(", "$HTTP_POST_VARS['agesort']);
    }
    else {
    $setage "2, 5, 3, 6, 4, 7";

    now if the age group was selected the box should be checked.... i don't know how to do this???

    PHP Code:

    <td width="121"><input type = "checkbox" name = "agesort[]" value = "2" <?php if ($setage == 2) { ?> checked <?php }?>/>
              13-17</td>

    <td width="114"><input type = "checkbox" name = "agesort[]" value = "5" <?php if ($setage == 5) { ?> checked <?php }?>/>
              36-45</td>

    Thanks!

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Haha, $HTTP_POST_VARS... haven't seen that one in a while
    Code:
    if(isset($_POST['agesort']) && array_reduce($_POST['agesort'], create_function('$a,$b', 'return $a && is_numeric($b);', true)
      $setage = $_POST['agesort'];
    else
      $setage = array(2, 5, 3, 6, 4, 7);
    
    for($i = 0; $i < count($setage); ++$i) {
    ?>
    <td>
      <input type="checkbox" name="agesort[]" value="<?php echo $setage[$i]; ?>" checked="checked">
    </td>
    <?php } ?>
    Code:
    <td width="114"><input type = "checkbox" name = "agesort[]" value = "5" <?php if ($setage == 5) { ?> checked <?php }?>/>
    Your markup is broken -- you're using XHTML-style self-closing tags, but a binary attribute without a value. The two are mutually exclusive, and I doubt you're serving XHTML anyway (since it would have failed to parse at that). Stick with HTML unless you really know what you're doing.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •