i had two list boxes and two submit buttons.Submit button is used to populate the items from one select box into another and vice versa. When the form is submitted the selectBox2.value must be passed to php file.
<SCRIPT LANGUAGE=”JavaScript” TYPE=”text/javascript”>
function MoveOption(objSourceElement, objTargetElement)
{
var values= new Array();
var aryTempSourceOptions = new Array();
var x = 0;
//looping through source element to find selected options
for (var i = 0; i < objSourceElement.length; i++) {
if (objSourceElement.options[i].selected) {
//need to move this option to target element
var intTargetLen = objTargetElement.length++;
objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
}
else {
//storing options that stay to recreate select element
var objTempValues = new Object();
objTempValues.text = objSourceElement.options[i].text;
objTempValues.value = objSourceElement.options[i].value;
aryTempSourceOptions[x] = objTempValues;
x++;
}
}
//resetting length of source
objSourceElement.length = aryTempSourceOptions.length;
//looping through temp array to recreate source select element
for (var i = 0; i < aryTempSourceOptions.length; i++)
{
objSourceElement.options[i].text = aryTempSourceOptions[i].text;
objSourceElement.options[i].value = aryTempSourceOptions[i].value;
objSourceElement.options[i].selected = false;
}
}
function posted_values(objTargetElement)
{
var values= new Array();
// var aryTempSourceOptions = new Array();
for (var i = 0; i < objTargetElement.length; i++)
{
values[i]= objTargetElement.options[i].value;
}
//document.write(values);
return (values);
}
</script>
<html>
<form name=”theForm” action=”<?=$PHP_SELF?>” method=”post” onSubmit=”return posted_values(theForm.sDisabled);”>
<select name=”sEnabled” size=”5″ multiple style=”width: 100px;”>
<option value=” 1″>Option 1</option>
<option value=” 2″>Option 2</option>
<option value=” 3″>Option 3</option>
<option value=” 4″>Option 4</option>
<option value=” 5″>Option 5</option>
<option value=” 6″>Option 6</option>
</select>
<input type=”button” name=”Disable” value=” Disable -> ” style=”width: 100px;” onClick=”MoveOption(this.form.sEnabled, this.form.sDisabled)”><br>
<br>
<input type=”button” name=”Enable” value=” <- Enable ” style=”width: 100px;” onClick=”MoveOption(this.form.sDisabled, this.form.sEnabled)”><br>
<select name=”sDisabled” size=”5″ multiple style=”width: 100px;”>
<option value=”Option 7″>Option 7</option>
<option value=”Option 8″>Option 8</option>
</select>
<?php
for($i = 0; $i < sizeof($array); $i++)
{
// echo ‘<input type=”checkbox” name=”theArray[]” id=”box’.$i.'” value=”‘.$array[“$i”].'”>’.$array[“$i”].”n”;
}
?>
<input type=”submit” value=”Submit” />
</form>
</html>
<?php
print_r($_POST);exit;
?>
The problem here is the function named “posted_values(objTargetElement)
” returns values but its not able to return all the values in selectBox2 instead it returns only those values selected in the selectBox2 while the form is submitted.
with regards.
james