#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    20
    Rep Power
    0
    I am trying to use a for that has 12+ unique checkboxes in an html form. I am trying to use the results from those checkboxes in an if statement (if(checkbox1=checked){}). The checkboxes are named checkbox0-checkbox11. Is there a way that I can put the if statement into a loop and access all of the checkboxes in turn (i.e. for($i=0;$i<11;$i++){if statement})
    I have tried $checkbox.$i and that didn't work. I get the right result if I statically type in $checkbox5 (or whatever number) but not getting it through a loop.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    16
    Read the STDIN (asuming you used the POST method) and put each element that contains "checkbox" into that array. Then you can loop through the array.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Dallas, TX USA
    Posts
    3
    Rep Power
    0
    In your form html, name the checkboxes with the array brackets, like this:

    <input type='checkbox' name='checkArray[]'>

    On the server, loop through the checkbox array:

    for($i=0;i<12;i++){if($checkArray[$i] == "on"){doSomething();}}

    Hope that helps. It's major pseudo code, but I've made it work before really similar on several occasions.

    [This message has been edited by gcraig (edited August 01, 2000).]
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    24
    Rep Power
    0
    If you still wanted to use the name checkbox0 - checkbox11 i think you could use the eval() function

    for($i=0;$i<11;$i++){
    eval("if($checkbox$i){}");
    }

    You would have to try it out though. I have used it but not with an if statment so I don't know for sure it it will work.


    ------------------
    Aoeex,

    -http://www.aoeex.com
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    58
    Rep Power
    15
    Even simpler Aoeex.

    Use the {} curly brackets.

    for($i=0;$i<11;$i++){
    echo ${"checkbox".$i}"};
    }

    ------------------

    peterbe.com

Similar Threads

  1. read iframe html.....write to form, string..etc.
    By dave777 in forum HTML Programming
    Replies: 0
    Last Post: February 2nd, 2004, 12:27 PM
  2. read iframe html.....write to form, string..etc.
    By dave777 in forum PHP Development
    Replies: 2
    Last Post: February 2nd, 2004, 10:11 AM
  3. Can php be used in html files
    By emzyme in forum PHP Development
    Replies: 3
    Last Post: January 29th, 2004, 01:50 PM
  4. all-in-one php script displaying html
    By emzyme in forum PHP Development
    Replies: 5
    Last Post: January 27th, 2004, 07:07 AM
  5. php n00b. Put a php file into an html template?
    By WorldBuilder in forum PHP Development
    Replies: 3
    Last Post: January 25th, 2004, 08:48 PM

IMN logo majestic logo threadwatch logo seochat tools logo