I want to use Javascript to move items from a source list to a destination list and then PHP to retrieve the items in the destination list. After much head bashing and pointers from various forum archives I am nearly there! Can anyone help me?

My remaining problem is that the array that PHP sees only has the final few characters of the values it should have.

This is the result of print_r after selecting two items (analysis1 and analysis3):

Array ( [0] => ysis1 [1] => ysis3 )

expecting:

Array ( [0] => analysis1 [1] => analysis3 )


Here is the code:

<script language="JavaScript">
<!--

// select all items in destination list on submit

function selectAll() {
destList = window.document.forms[0].elements[2];
for(n = 0; n < destList.length; n++) {
destList.options[n].selected=true;
} //for
}// selectAll


// Add the selected items from the source to destination list
function addSrcToDestList() {
destList = window.document.forms[0].elements[2];
srcList = window.document.forms[0].elements[0];
var len = destList.length;
for(var i = 0; i < srcList.length; i++) {
if ((srcList.options[i] != null) && (srcList.options[i].selected)) {
//Check if this value already exist in the destList or not
//if not then add it otherwise do not add it.
var found = false;
for(var count = 0; count < len; count++) {
if (destList.options[count] != null) {
if (srcList.options[i].text == destList.options[count].text) {
found = true;
break;
}
}
}
if (found != true) {
destList.options[len] = new Option(srcList.options[i].text);
destList.options[len].value=srcList.options[i].value
len++;
}
}
}
}
// Deletes from the destination list.
function deleteFromDestList() {
var destList = window.document.forms[0].destList;
var len = destList.options.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
destList.options[i] = null;
}
}
}
// End -->
</SCRIPT>
<html>
<head>
<title>Edit Preferences</title>
</head>
<body >
<?php
print_r($_POST['destList']);
?>
<form method="post" name="form2" onSubmit="javascript:selectAll();">
<table width="80%" border="0">
<tr>
<td>Current Order</td>
<td width="75">&nbsp;</td>
<td>New Order</td>
</tr>
<tr>
<td rowspan="3">

<select name="srcList[]" size=10 >
<option value="analysis1">Product</option>
<option value="analysis2">Source</option>
<option value="analysis3">Contact</option>
<option value="date1">Order Date</option>
<option value="number3">Gross</option>
<option value="number2">VAT</option>
<option value="number1">Nett</option>
</select>

</td>
<td width="75"> <input type="button" value=" << " onclick="javascript:deleteFromDestList();">
<td rowspan="3">

<select name="destList[]" size="10" multiple id="select2">
</select></td>
</tr>
<tr>
<td width="75"> <input type="button" value=" >> " onClick="javascript:addSrcToDestList()">
</td>
</tr>
<tr>
<td width="75">&nbsp;</td>
</tr>
<tr>
<td><input name="UpdateOrder" type="submit" value="Update Record"></td>
<td width="75">&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>


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

Reply via email to