Re: checkbox validation

From: Date: Wed, 18 Apr 2001 14:28:19 +0000
Subject: Re: checkbox validation
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-50170@lists.php.net to get a copy of this message
Hi jacky, put an empty square bracket after the variable name as follows: <input type="checkbox" name="id[ ]" value="$id"> assuming that your above statement is in a loop we will have following structure: ********************************* <form> <input type="checkbox" name="id[ ]" value="$id"> <input type="checkbox" name="id[ ]" value="$id"> <input type="checkbox" name="id[ ]" value="$id"> etc... <submit button> </form> ************************************ now when you submit the form, an array named id[ ] will be posted . this array will contain the number of elements/checkbox which were checked on. so out of 25 checkboxes if you select only 5 checkboxes, then the size of the array id[ ] will be only 5. so with another loop you can retrieve all the values as follows: *********************************** $i=0; while($i<sizeof($id): $id[$i]=="blah"; $i++; endwhile; *********************************** sorry for the poor explanation but i hope this will serve your purpose. if you have any queries with this feel free to contact me. regards keyur $$$$$$$ ----- Original Message ----- From: "Jacky" <jacky@activelifestyle.com> To: <php-general@lists.php.net> Sent: Thursday, April 19, 2001 1:13 AM Subject: [PHP] checkbox validation Hi all I have a form with the checkbox like this <form> $query="select id from foo"; $result=($query,$con); while ($row = mysql_fetch_array($result)) { <input type="checkbox" name="$id" value="on"> } ....submit button and stuffs here... </form> After I submit to next page, at next page, how do I check which check box is checked? like this? if ($id=="on") { do something }else{ do something } I did try this but did not work, what am i suppose to do to achieve this? Jack jacky@activelifestyle.com "There is nothing more rewarding than reaching the goal you set for yourself"

« previous php.general (#50170) next »