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

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    Hi all!
    I have several checkboxes in a html form (array). In PHP perform a count:

    if (!isset($checkboxes)){
    $count_checkboxes="0";}
    else{
    $count_checkboxes=count($checkboxes);}

    echo "$count_checkboxes";

    none of the checboxes is checked by default in my html form. However, even when no one is selected, $count_checkboxes returns "1" in PHP
    Do I have to reset $checkboxes somehow???
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Washington, USA
    Posts
    52
    Rep Power
    14
    Maybe try changing to this:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $sizeof = count($checkboxes);
    for($i=0; $i < $sizeof; $i++) {
    if($checkboxes[$i] != "") {
    $count_checkboxes++;
    }
    }
    echo "$count_checkboxes";
    [/code]

    Unlike the Perl $# function which returns zero as the size of an array with 1 indexed item, PHP returns 1 using the count($array) function and same criteria.


    ------------------
    <UL TYPE=SQUARE>
    <LI> TD Scripts
    <LI> Script School
    <LI>php-scripts
    </UL>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    thank you SO much!!!!!!!!!!!
    i suspected something like that but was not sure, could not find the info, and thus did not know how to code the script to turn around...
    i know i'm over-reacting a bit, but this was annoying me for a few days so thanks again!!!!

Similar Threads

  1. print selected files from a table
    By cindykk in forum HTML Programming
    Replies: 1
    Last Post: February 11th, 2004, 12:52 AM
  2. get multiple selected item from a listbox in JSP
    By saurabhvaidya in forum Java Help
    Replies: 0
    Last Post: January 5th, 2004, 12:32 AM
  3. <SELECT>: onchange for already selected item
    By Tupax in forum HTML Programming
    Replies: 2
    Last Post: September 18th, 2003, 06:03 AM
  4. Replies: 5
    Last Post: February 6th, 2003, 06:23 AM
  5. How do I shorten marking select boxes "selected"
    By Little John in forum Perl Programming
    Replies: 10
    Last Post: December 27th, 2001, 06:23 PM

IMN logo majestic logo threadwatch logo seochat tools logo