Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select multiple values from a <select> box

Status
Not open for further replies.

KingSlick

Programmer
Mar 9, 2007
45
US
I am using AJAX to remove selections from a DB. These selections are listed inside of a <select> box. I am able to remove one sleection at a time, however, I am trying to be able to remove multiple selections at a time.

See code below...

Code:
function removeCompany(profile, selBox) {
    if (searchReq.readyState == 4 || searchReq.readyState == 0) {
        var box = document.getElementById("Select1");
        var str = '';
        var val;
        str = box.options[box.selectedIndex].text.replace(/&/g,"*amp*");
        //alert(str);
        searchReq.open("GET", 'ajaxRemove.php?t=CompanyName&p=' + profile + '&str=' + str , true);
        searchReq.onreadystatechange = removeCompanySelect;
        searchReq.send(null);

    }
}

Now what I would like to be able to do is get the selected values and have those become the "str" variable, as a comma delimited string. However, I haven't been able to get a loop to get all of the values to be added to the str.

any help would be great.

Thanks
 
Here are the two functions I use when dealing with multiple select boxes...
function addUser() {
var f = document.frmHelpDeskItem;
var fl = f.resources.length -1;
var au = f.assigned.length -1;
var users = "x";

//build array of assiged users
for (au; au > -1; au--) {
var ul = f.assigned.options[au].value.split("-");
users = users + "," + ul[1] + ","
}

//Pull selected resources and add them to list
for (fl; fl > -1; fl--) {
if (f.resources.options[fl].selected && users.indexOf( "," + f.resources.options[fl].value + "," ) == -1) {
t = f.assigned.length
opt = new Option( "O " + f.resources.options[fl].text, "1-" + f.resources.options[fl].value );
f.assigned.options[t] = opt
}
}
}

function removeUser() {
var f = document.frmHelpDeskItem;
fl = f.assigned.length -1;

for (fl; fl > -1; fl--) {
if (f.assigned.options[fl].selected) {
f.assigned.options[fl] = null;

}
}

}

Box 1 (resources) contains all users, box 2 contains assignments. You can adapt to your program.

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top