...

View Full Version : Adding values to a multi select list box



veebster
06-10-2004, 04:39 AM
My Scenario.....

I have a page that contains an empty multi select list box (main page). On the main page is an add products link.
When you click this link it opens a pop up window that display’s a list of products.

I want to be able to click on multiple table row's (not tick a box) and have the row id's appear in the multi select box on the main page.

Is this possible?

Thanks in advance

glenngv
06-10-2004, 05:17 AM
in main page:


function addOption(objTargetSel, text, value){
objTargetSel.options[objTargetSel.length] = new Option(text, value);
}

in popup page:


function addOption(text, value){
if (opener && !opener.closed){
opener.addOption(opener.document.theFormName.theSelectName, text, value);
}
else {
alert("The parent window is closed.");
}
}
...
<tr id="blah" onclick="addOption(this.id, this.id)">

The addOption function in the main page is generic, you can use it in any select element. If you are only using it to only one select box, you can simplify it by removing the objTargetSel as parameter.


function addOption(text, value){
var objTargetSel = document.theFormName.theSelectName;
objTargetSel.options[objTargetSel.length] = new Option(text, value);
}

Then in the popup:


if (opener && !opener.closed){
opener.addOption(text, value);
}
...

veebster
06-10-2004, 06:27 AM
You are a champion!

veebster
06-11-2004, 07:05 AM
How can I add a button that when pressed removes any selected items in the multi select box?

Thanks!

glenngv
06-11-2004, 09:03 AM
Just set the length property of the options array to 0.


function deleteAllOptions(){
document.theFormName.theSelectName.options.length=0;
}

Ohh, I thought you want to delete all options..
Ok, here's the real code:


function deleteSelectedOptions(){
var s = document.theFormName.theSelectName;
for (var i=s.options.length-1;i>=0;i--){
if (s.options[i].selected){
s.options[i] = null;
}
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum