/* IE4+ ONLY !!!!!!!
it is suposed that :
the form name is my_form;
the listbox which we want to change the content is my_listbox;
the datas we want to display in it are stored in an my_array (yes, everything is mine ! ;-));
my_array is 2dimensionnal : my_array[x][0] is the value, my_array[x][1] is the text corresponding to the value
*/
my_listbox=document.my_form.my_listbox
//------------
//POPULATING MY_LISTBOX WITH MY_ARRAY VALUES
// in : nothing; out : true (always ;-) !)
function fill_my_listbox()
{
// first, remove all what is in the listbox
while (my_listbox.options.length!=0)
my_listbox.options.remove(0);
// now, fill it !
for (var m=0; m<my_array.length; m++)
// if you conditionnaly fill the list, put the condition here (for exemple : if (my_array[m][1]>"whatever"))
{
var oOption = document.createElement("OPTION");
oOption.text=my_array[m][1];
oOption.value=my_array[m][0];
my_listbox.options.add(oOption)
}
return true;
}
//---------------
//ADDING JUST ONE OPTION TO MY_LISTBOX
// in : text is the text of the added option, value its value; out : true (always ;-) !)
function add_one_option (text, value) {
var oOption = document.createElement("OPTION");
oOption.text=text;
oOption.value=value;
my_listbox.options.add(oOption)
return true;
}
//--------------
//REMOVING JUST ONE OPTION FROM MY_LISTBOX
// in : my_value the value of the option you want to remove; out : boolean
function rem_one_option(my_value) {
var my_index=-1
for (var m=0; m<my_listbox.options.length; m++) // first we have to retrieve the index ! if someone knows a better function ... i'm sure there is ...
if (my_listbox.options[m].value==my_value)
my_index=m;
// so now the index should be in my_index
if (my_index==-1) // someting wrong happened
{
alert("well i'm not able to find the index of the element corresponding to the value "+my_value)
return false;
}
else
my_listbox.options.remove(my_index)
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.