I am needing to make a section in a form that allows for multiple check boxes to be selected and then and most importantly it has to be writen to a database .

basicly I would like to be able to do is one of two things , the preferable is to check which boxes are ticked and then slot them into data1 data2 and data3 in the database
my other alternative and less prefered is to put them all into one field and seperate the values with a / or ,
the script bellow pretty much does what i want except it echo's the responce in an alert when you click the output button what I need this script to do is run the script as I submit the form , and then pass the value's over to the processing page so that I can assign them to a variable and slot em into the database

         function getSelected(opt) {
            var selected = new Array();
            var index = 0;
            for (var intLoop = 0; intLoop < opt.length; intLoop++) {
               if ((opt[intLoop].selected) ||
                   (opt[intLoop].checked)) {
                  index = selected.length;
                  selected[index] = new Object;
                  selected[index].value = opt[intLoop].value;
                  selected[index].index = intLoop;
               }
            }
            return selected;
         }

     function outputSelected(opt) {
        var sel = getSelected(opt);
        var strSel = "";
        for (var item in sel)       
           strSel += sel[item].value;
        alert("Selected Items:\n" + strSel);
     }
     

and then the form

 
       <FORM method="post" action="test2.php" NAME="ColorSelector">
     <INPUT TYPE=CHECKBOX NAME="color" VALUE="Red">Red
     <INPUT TYPE=CHECKBOX NAME="color" VALUE="Navy" CHECKED>Navy
     <INPUT TYPE=CHECKBOX NAME="color" VALUE="Black">Black
     <INPUT TYPE=CHECKBOX NAME="color" VALUE="White" CHECKED>White
     <INPUT TYPE=BUTTON VALUE="Selected Check Box Items" 
        ONCLICK="outputSelected(this.form.color);">
        <input name="submit" type="submit" value="Submit Report">
     <P>
  </FORM>
  

I have also tried to set ONCLICK="outputSelected(this.form.color); on the submit button , however this ofcourse didn't work because I had no idea how the variable was passed or if it was at all 🙁

sorry for the delay I was havign huge problems replying , which turned out to be the script tages in my script

I guess in summary what I need to know is how I can I pass the value of sel[item].value onto my form processing page so that
I can assign it a phpo variable and put it into my database

    It sounds like this is more of a javascript question.

    If you want to check what values you are passing, you can always add this to the top of test2.php

    echo('<pre>');
    print_r($_POST);
    die();
    

    This will output all your form variables nicely formatted so you can see exactly what you are passing across. Of course, remove these 3 lines once you have finished or your script won't work!

    basicly I would like to be able to do is one of two things , the preferable is to check which boxes are ticked and then slot them into data1 data2 and data3 in the database
    my other alternative and less prefered is to put them all into one field and seperate the values with a / or ,

    The second option shouldn't be less prefered, it should be ignored completely. The general rule for databases is to make each column hold one item of data (e.g. data1). Putting them all into one column is just asking for trouble. If your list of checkboxes is fixed and finite (i.e. you have four and this is unlikely ever to change much) you could have them as columns

    id_field
    ...
    data1
    data2
    data3
    

    If the number of checkboxes is variable, you might want to split them and use a number of tables

    table1
    -------
    id_field
    ...
    
    table2
    --------
    data_id
    data_label
    
    table3
    --------
    data_id
    id_field
    data_value
    
      Write a Reply...