Move selected options from one listbox to another

The first listbox is generated dynamically using ajax

Page 1 of 1

0 Replies - 3707 Views - Last Post: 16 August 2009 - 10:49 PM

#1 dodsonjt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-June 09

Move selected options from one listbox to another

Post icon  Posted 16 August 2009 - 10:49 PM

My question is why doesn't my javascript function "move" see the from box(fbox) when I pass the listbox by id to it.

The program that I am coding has a requirement to allow the user to select from list of options and move those selections to the "assigned" listbox

The first listbox is generated dynamically using an ajax call to execute a PHP script that retreives some options from a database then formats the html for the listbox and passes it back to the ajax response function. The ajax response function then executes the following code;

function SubSMCResponse() {

if (mySubReq.readyState == 4) {
//alert("SubSMC Status: "+mySubReq.status);
if(mySubReq.status == 200) {
result = mySubReq.responseText;
document.getElementById('tmAvailSubSMC').innerHTML = result;
} else {
try{alert("There was an issue retrieving the Departments data:\n" +
"Reason: " + mySubReq.statusText);
}
catch(e){
alert("There was an issue retrieving the Departments data:\n" +
"Reason: " + mySubReq.statusText);
}
alert('There was a problem with the request for Departments.');
}
} else {
document.getElementById('tmAvailSubSMC').innerHTML = '<img src="../assets/images/indicator-big-2.gif"/>';
}

}

This works fine. The listbox displays fine with all the options.

At this point there are two listboxes displayed with two directional buttions between them. The problem occurs after I select the options that I would like to assign and press one of the directional buttons. onclick these buttons execute the javascript function "move". When I put an alert to display the contents of fbox as the first statement of this function it show the fbox as undefined;

<script language="Javascript">
<!-- Begin
function move(fbox, tbox) {
alert ("fbox: "+ fbox);
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
} else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
}
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
}
}

I have attached the team.php file which contains all the html and php code used to desplay this screen. There are three different tabs in this file the one that this question is concerning is "LayoutRegion4LYR"

Attached File(s)

  • Attached File  team.php (64.67K)
    Number of downloads: 97


Is This A Good Question/Topic? 0
  • +

Page 1 of 1