Thank's for the help everybody!

I used something different (a little like this nice one from Terence (thank
you!) but with JS:

I named my form 'test' and included a hidden field 'collector'.
At the checkboxes the name is the value I need. The box, when checked, gets
the value 1.

In the boxtags I added:
where name is the value I want.

Then I wrote this little script:
 $js = "<script type=text/javascript>
 function add_values(val) {
   document.test.'collector'.value += val;
   document.test.'collector'.value += \",\";

It produces a comma separated list in the field 'collector' whith only the
checked values.
When sending the form, only this field is transmitted. This is just what I
wanted and it works fine.


Terence Kearns schrieb in Nachricht
>This is a nice easy one :)
>It couldn't be simpler.
>Just put empty square brackets (as used in arrays) in front of your
>checkbox name.
>The example below assumes you have PHP 4.1 or greater (which uses
>$_POST to contain form posted data)
>notice how name="ck[]"
> <title>Untitled</title>
>    if(count($_POST)) {
>        foreach ($_POST["ck"] as $varval) {
>            print("<div>".$varval."</div>");
>        }
>    }
><form action="test.php" method="post">
><input type="checkbox" name="ck[]" value="val1"><br>
><input type="checkbox" name="ck[]" value="val2"><br>
><input type="checkbox" name="ck[]" value="val3"><br>
><input type="checkbox" name="ck[]" value="val4"><br>
><input type="checkbox" name="ck[]" value="val5"><br>
><input type="submit">
>in earlier versions of PHP, $_POST["ck"] would be equal to $ck
>(although, the former is safer)
>On Thu, 4 Jul 2002 10:52:37 +0200, "Uwe Birkenhain"
>> Hi everybody on this rainy morning!
>> My problem:
>> I give the user a form with a list of options with checkboxes.
>> The list is long and not predictable - the values change always.
>> I want to put the checked values (or all, that doesn't matter) in an
>> array,
>> to pass it to my function.
>> How can I write those keys and values in an array?
>> I suppose it will be best done with JS - but since I don't know JS ...
>> Has anybody a ready solution?
>> Thank's a lot!
>> Uwe
>> --
>> PHP General Mailing List (
>> To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to