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