Hi,
I have a combo box which contains a no of values.On selecting any of these values and clicking a button,the selected value should get added to a multi select list(dynamically).And on selecting any value from the multi selection list and clicking another button ,the selected value should get removed from the multi selection list.Can anybody help.
Dynamic multi selection box
Moderator: General Moderators
I've had the same problem some time ago -here is what I came up with. If I remember correctly, this one only works in IE.
form-name is "alerts"
Alternatively, have a look at JavaScript Toolbox, especially Dynamic Options List, Selectbox Functions and Option Transfer.
That stuff is definitely cross-browser.
form-name is "alerts"
Code: Select all
function addToSelect(selectList,newOption,newValue)
{
for (i=1;i<document.forms.alertsїselectList].options.length;i++)
{
if (document.forms.alertsїselectList].optionsїi]==newOption || document.forms.alertsїselectList].optionsїi].text==newValue)
{document.forms.alertsїselectList].optionsїi] = new Option(newOption,newValue); return;}
}
document.forms.alertsїselectList].optionsїdocument.forms.alertsїselectList].options.length] = new Option(newOption,newValue);
}
function deleteSelect(selectList,deleteOption)
{
for (i=1;i<document.forms.alertsїselectList].options.length;i++)
{
if (document.forms.alertsїselectList].optionsїi]==deleteOption || document.forms.alertsїselectList].optionsїi].text==deleteOption)
{document.forms.alertsїselectList].optionsїi] = null; return;}
}
}
function updateSelect(selectList,oldOption,updateText,updateOption)
{
// selectList="document.forms.alertsїselectList]";
for (i=1;i<document.forms.alertsїselectList].options.length;i++)
{
if (document.forms.alertsїselectList].optionsїi]==oldOption || document.forms.alertsїselectList].optionsїi].text==oldOption)
{
document.forms.alertsїselectList].optionsїi].text = updateText;
if (!updateOption)
updateOption=updateText;
document.forms.alertsїselectList].optionsїi].value = updateOption;
return;
}
}
}Alternatively, have a look at JavaScript Toolbox, especially Dynamic Options List, Selectbox Functions and Option Transfer.
That stuff is definitely cross-browser.