Buzzle
06-22-2009, 11:12 PM
Hey all,
I have 2 select windows and have a function to move items from one select window to another. That was working fine until I had to change the names of each box in order to be able to post the select window as an array in PHP.
<select size="10" name="select_list1[]" id="select_list1[]" MULTIPLE>
<select size="10" name="select_list2[]" id="select_list2[]" MULTIPLE>
This is the function call:
<input type="button" value=" --> " onClick="SelectMoveRows(document.form.select_list1, document.form.select_list2);"/>
And this is the function that moves the options from one window to the other:
function SelectMoveRows(SS1,SS2) {
var SelID='';
var SelText='';
// Move rows from SS1 to SS2 from bottom to top
for (i=SS1.options.length - 1; i>=0; i--) {
if (SS1.options[i].selected == true) {
SelID=SS1.options[i].value;
SelText=SS1.options[i].text;
var newRow = new Option(SelText,SelID);
SS2.options[SS2.length]=newRow;
SS1.options[i]=null;
}
}
}
The errors I am getting now are:
Error: SS1 is undefined
and if I try to change the function call (adding []'s), I get a syntax error because of it.
Error: syntax error
Source Code:
SelectMoveRows(document.form.select_list1[], document.form.select_list2[]);
How can I change the functions so that it accepts the square brackets? They are necessary unless you know of a better way to post a select form in PHP.
Thanks for any information.
I have 2 select windows and have a function to move items from one select window to another. That was working fine until I had to change the names of each box in order to be able to post the select window as an array in PHP.
<select size="10" name="select_list1[]" id="select_list1[]" MULTIPLE>
<select size="10" name="select_list2[]" id="select_list2[]" MULTIPLE>
This is the function call:
<input type="button" value=" --> " onClick="SelectMoveRows(document.form.select_list1, document.form.select_list2);"/>
And this is the function that moves the options from one window to the other:
function SelectMoveRows(SS1,SS2) {
var SelID='';
var SelText='';
// Move rows from SS1 to SS2 from bottom to top
for (i=SS1.options.length - 1; i>=0; i--) {
if (SS1.options[i].selected == true) {
SelID=SS1.options[i].value;
SelText=SS1.options[i].text;
var newRow = new Option(SelText,SelID);
SS2.options[SS2.length]=newRow;
SS1.options[i]=null;
}
}
}
The errors I am getting now are:
Error: SS1 is undefined
and if I try to change the function call (adding []'s), I get a syntax error because of it.
Error: syntax error
Source Code:
SelectMoveRows(document.form.select_list1[], document.form.select_list2[]);
How can I change the functions so that it accepts the square brackets? They are necessary unless you know of a better way to post a select form in PHP.
Thanks for any information.