----- Original Message -----
From: "shaun" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, March 21, 2003 12:25 PM
Subject: [PHP] php and javascript


> Hi,
>
> I'm not sure if this is a PHP or a JavaScript question but I have found
the
> following code to enable me to select all of the checkboxes on my form.
>
> <SCRIPT LANGUAGE="JavaScript">
> <!-- Begin
> var checkflag = "false";
> function check(field) {
> if (checkflag == "false") {
>   for (i = 0; i < field.length; i++) {
>   field[i].checked = true;}
>   checkflag = "true";
>   return "Uncheck all"; }
> else {
>   for (i = 0; i < field.length; i++) {
>   field[i].checked = false; }
>   checkflag = "false";
>   return "Check all"; }
> }
> //  End -->
> </script>
>
> <form name=mon_formulaire action="" method=post>
> <table>
> <b>Where do you connect to the Internet from?</b><br>
> <input type=checkbox name=list value="1">Home<br>
> <input type=checkbox name=list value="2">Office<br>
> <input type=checkbox name=list value="3">Friends' home<br>
> <input type=checkbox name=list value="4">Post office<br>
> <input type=checkbox name=list value="5">Internet Café<br>
> <br>
> <input type=button value="Check all"
> onClick="this.value=check(this.form.list)">
> </form>
>
> The problem is that in the example all of the boxes are called list and i
> need to name each checkbox on my form with a different user_id so that i
can
> collect the data sent from the form, is there a way around this?
>
> Thanks in advance for any advice offered.


I see a number of possible solutions through PHP.  The way that I would
handle this is to give each group its own numerical id.  So something like..

Group #1
<input type="checkbox" name="list_1[]" value="1">Home<br>
<input type="checkbox" name="list_1[]" value="2">Office<br>
<input type="checkbox" name="list_1[]" value="3">Friends' home<br>

Group #2
<input type="checkbox" name="list_2[]" value="1">Home<br>
<input type="checkbox" name="list_2[]" value="2">Office<br>
<input type="checkbox" name="list_2[]" value="3">Friends' home<br>

Then in my script each group array can be accessed with something like this.

<?
$num_groups = 2;
for($i=1; $i<=$num_groups; $i++)
{
 echo "<b>GROUP #$i</b><br>";
 for($j=0; $j<count($_POST['list_'.$i]); $j++)
 {
  echo $_POST['list_'.$i][$j]."<br>";
 }
}
?>

If you need to define each group with a userid then you cuold store those
ids in an array and use ereg() in a loop to parse the groups.

HTH,
Kevin



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to