Hi all,
I am currently having trouble passing multiple selected values from a select box. Currently, when the form is submitted, it is only passing the last value of the selected items.
Any ideas on how to send all selected values?
Here is the code so far:
<?
if ($_POST['add_prod']){
echo $_POST['list2'] . "<BR>";
exit;
} else {
?>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
sortitems = 1; // Automatically sort items within lists? (1 or 0)
function move(fbox,tbox) {
for(var i=0; i<fbox.options.length; i++) {
if(fbox.options[i].selected && fbox.options[i].value != "") {
var no = new Option();
no.value = fbox.options[i].value;
no.text = fbox.options[i].text;
tbox.options[tbox.options.length] = no;
fbox.options[i].value = "";
fbox.options[i].text = "";
}
}
BumpUp(fbox);
if (sortitems) SortD(tbox);
}
function BumpUp(box) {
for(var i=0; i<box.options.length; i++) {
if(box.options[i].value == "") {
for(var j=i; j<box.options.length-1; j++) {
box.options[j].value = box.options[j+1].value;
box.options[j].text = box.options[j+1].text;
}
var ln = i;
break;
}
}
if(ln < box.options.length) {
box.options.length -= 1;
BumpUp(box);
}
}
function SortD(box) {
var temp_opts = new Array();
var temp = new Object();
for(var i=0; i<box.options.length; i++) {
temp_opts[i] = box.options[i];
}
for(var x=0; x<temp_opts.length-1; x++) {
for(var y=(x+1); y<temp_opts.length; y++) {
if(temp_opts[x].text > temp_opts[y].text) {
temp = temp_opts[x].text;
temp_opts[x].text = temp_opts[y].text;
temp_opts[y].text = temp;
temp = temp_opts[x].value;
temp_opts[x].value = temp_opts[y].value;
temp_opts[y].value = temp;
}
}
}
for(var i=0; i<box.options.length; i++) {
box.options[i].value = temp_opts[i].value;
box.options[i].text = temp_opts[i].text;
}
}
// End -->
</script>
<FORM action="<? $PHP_SELF ?>" name="product_form" method="post" enctype="multipart/form-data">
<table width=400>
<tr>
<td align="left" colspan="2">Product Category:</td>
</tr>
<tr>
<td align="left" colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1">
<select multiple name="list1" size="5">
<?
include ("include/cart_dbconnect.php");
mysql_select_db(gurud04_cartdata1);
$query_categories = mysql_query("select * from cart_categories where cat_parent=0");
while($row = mysql_fetch_array($query_categories)){
$cat_id = $row['cat_id'];
$cat_name = stripslashes($row['cat_name']);
?>
<option value="<? echo $cat_id ?>"><? echo $cat_name ?></option>
<?
}
?>
</select></td>
<td width="1"><table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td><input type="button" value=" >> " onclick="move(this.form.list1,this.form.list2)" name="B12" style="font-size:8px">
<br>
<input type="button" value=" << " onclick="move(this.form.list2,this.form.list1)" name="B22" style="font-size:8px"></td>
</tr>
</table></td>
<td><select multiple size="5" name="list2">
<option value="" > </option>
</select></td>
</tr>
<tr>
<td align="right"><br><input name="add_prod" type="submit" value="Submit"></td>
</tr>
</table>
</FORM>
<?
}
?>
Cheers,
macca