S
SM
Hello,
Im creating a combobox using the Javascript and the DOM.
If the combobox exists, i don't want to create another one. I want to
empty all the values and put new values.
I was able to create the combox and create the lines of code that
deletes the values in the combobox (well almost)
I just need help finishing my function
Thanks
Marco
function show_catalog()
{
...
if (???combobox doesnt exist, create one)
{
form = document.createElement("form");
selectElem = document.createElement("select");
selectElem.setAttribute("name", "video");
selectElem.setAttribute("size", "1");
form.appendChild(selectElem);
...
}
else //empty existing one
{
while(???.options.length) {
???.remove(0);
}
}
//ok now fill the newly created combobox or the existing one now
empty
for (var x in catalog)
{
optionElem = document.createElement('option');
optionElem.setAttribute('value', i);
optionElemValue = document.createTextNode(x);
optionElem.appendChild(optionElemValue)
selectElem.appendChild(optionElem);
}
}
The first time, its always going to be empty, therefore its going to
create one (that the reference i will use to empty it when i click)
Im creating a combobox using the Javascript and the DOM.
If the combobox exists, i don't want to create another one. I want to
empty all the values and put new values.
I was able to create the combox and create the lines of code that
deletes the values in the combobox (well almost)
I just need help finishing my function
Thanks
Marco
function show_catalog()
{
...
if (???combobox doesnt exist, create one)
{
form = document.createElement("form");
selectElem = document.createElement("select");
selectElem.setAttribute("name", "video");
selectElem.setAttribute("size", "1");
form.appendChild(selectElem);
...
}
else //empty existing one
{
while(???.options.length) {
???.remove(0);
}
}
//ok now fill the newly created combobox or the existing one now
empty
for (var x in catalog)
{
optionElem = document.createElement('option');
optionElem.setAttribute('value', i);
optionElemValue = document.createTextNode(x);
optionElem.appendChild(optionElemValue)
selectElem.appendChild(optionElem);
}
}
The first time, its always going to be empty, therefore its going to
create one (that the reference i will use to empty it when i click)