I have 2 select boxes, with Javascript, that moves a selection from one to another. The one moved to is a multiple select box. To get all of the items in the box via PHP after submission I have named it "ToLB[]" .. with brackets for php array form submission. However, when I add the brackets, the Javascript will not move selections into it. And that's with adding the brackets to the appropriate places in Javascript. Help my friend!
Jim Null
Code:
<?php
print "<p>display post values</p>";
foreach($_REQUEST as $postname => $postvalue){
print "<strong>$postname: </strong>$postvalue<br>";
//$name is the name of the field, $value is the value.
}
?>
<html>
<head>
<script language="javascript">
function move(tbFrom, tbTo)
{
var arrFrom = new Array(); var arrTo = new Array();
var arrLU = new Array();
var i;
for (i = 0; i < tbTo.options.length; i++)
{
arrLU[tbTo.options[i].text] = tbTo.options[i].value;
arrTo[i] = tbTo.options[i].text;
}
var fLength = 0;
var tLength = arrTo.length;
for(i = 0; i < tbFrom.options.length; i++)
{
arrLU[tbFrom.options[i].text] = tbFrom.options[i].value;
if (tbFrom.options[i].selected && tbFrom.options[i].value != "")
{
arrTo[tLength] = tbFrom.options[i].text;
tLength++;
}
else
{
arrFrom[fLength] = tbFrom.options[i].text;
fLength++;
}
}
tbFrom.length = 0;
tbTo.length = 0;
var ii;
for(ii = 0; ii < arrFrom.length; ii++)
{
var no = new Option();
no.value = arrLU[arrFrom[ii]];
no.text = arrFrom[ii];
tbFrom[ii] = no;
}
for(ii = 0; ii < arrTo.length; ii++)
{
var no = new Option();
no.value = arrLU[arrTo[ii]];
no.text = arrTo[ii];
tbTo[ii] = no;
}
}
</script>
</head>
<body>
<hr />
<form name="combo_box" action="test.php" method="post">
<table><tr><td>
Select From<br>
<select multiple size="10" name="FromLB" style="width:150">
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Anguilla">Anguilla</option>
<option value="Antarctica">Antarctica</option>
<option value="Antigua and Barbuda">Antigua and Barbuda</option>
</select>
</select>
</td>
<td align="center" valign="middle">
<input type="button" onClick="move(this.form.FromLB,this.form.ToLB[]);" value="->"><br />
<input type="button" onClick="move(this.form.ToLB[],this.form.FromLB);" value="<-">
</td>
<td>
Selections Made<br>
<select multiple size="10" name="ToLB[]" style="width:150">
</select>
</td></tr></table>
<input type="submit" name="submit" value="submit" onmouseover="FillText()">
</form>
<hr />
</body>
</html>
Jim Null