#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 1999
    Location
    Fredericton, NB Canada
    Posts
    1
    Rep Power
    0
    If I choose more than one item in a checkbox list, PHP feeds back only the last choice. Why?

    For example, I select 'dogs', 'cats' and 'mice', it sets the variable to 'mice' only.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Location
    Netherlands
    Posts
    77
    Rep Power
    15
    You can put the results of all checked checkboxes in an array, let's say pets.

    <input type="checkbox" name=pets[] value="dog">Dog
    <input type="checkbox" name=pets[] value="cat">Cat
    etc.

    Only when a box is checked, PHP puts the value in the array pets[], starting with index 0.
    Then you can read out all the checked values from the array.

    Peter
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    4
    Rep Power
    0
    I'm trying to get an array working with a dynamic multiple select box. I have put the rusults in an array but am unsure of how to explode the array on my action page.

    If in the example below, someone selected both dog and cat, how could I send two emails to them. One about dogs and one about cats.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    31
    Rep Power
    15
    Here's something for both questions:
    ---
    ?>
    <form>
    Select:<br>
    <select name="checks[]" size=5 multiple>
    <option value="cats">Cats
    <option value="dogs">Dogs
    </select><br>

    Checkboxes:<br>
    <input type="checkbox" name="checks[]" value="dogs2">Dogs<br>
    <input type="checkbox" name="checks[]" value="cats2">Cats<br>
    </form>

    <?

    function send_mail_about($subject) {
    print $subject . "<br>n";
    }

    while(list($dummy,$value)=@each($checks)) {
    print send_mail_about($value);
    }
    ---

Similar Threads

  1. Help with checkboxes
    By PRETTYfromDAWGS in forum PHP Development
    Replies: 1
    Last Post: September 26th, 2003, 07:09 AM
  2. validating cascading checkboxes
    By kishored in forum Java Help
    Replies: 3
    Last Post: July 30th, 2003, 01:22 PM
  3. Forms and checkboxes
    By dante2010 in forum PHP Development
    Replies: 3
    Last Post: September 3rd, 2002, 01:59 PM
  4. Replies: 2
    Last Post: February 25th, 2002, 11:10 AM
  5. select all checkboxes
    By homerdooh in forum HTML Programming
    Replies: 5
    Last Post: January 29th, 2002, 04:41 PM

IMN logo majestic logo threadwatch logo seochat tools logo