473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Remove items from a combobox

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)

May 26 '07 #1
1 10499
On May 26, 7:00 pm, SM <servandomont...@gmail.comwrote:
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);
}
Replace the above with:

} else {
selectElem.options.length = 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);
Replace the above with:

selectElem.options[selectElem.options.length] =
new Option(optText, optValue);
--
Rob

May 26 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Piet | last post by:
Hello wxPythoneers. I have a problem with a dialog box derived from wxFrame which has a wxComboBox as main element. Depending on the entry selected from the ComboBox, the dialog box will be...
3
by: Wayne Wengert | last post by:
I am trying to populate a combobox with a lisy of items. I want the 1st item to be "Make a Selection" and the following items will be names from a table in my DB (See code below). When I run the...
0
by: tupolev | last post by:
Hi, I already post this item but now I know whats wrong: I want to allow the user to edit the items in a combobox. The problem is that the textchange event works just one time (for the first...
3
by: Don | last post by:
My user control has a combobox with an arraylist attached to it along with custom add and remove methods. The "Add" method is working great. However I don't understand why the "Remove" method...
5
by: Wally | last post by:
I need to browse all ITEMS of a ListBox and all ITEMS of a ComboBox. I wrote 2 distinct Sub that are almost identical. The difference is only the object type. How could I browsing ITEMS using only...
9
by: Don | last post by:
Is there any way to detect when an item has been added to the Items collection of a combobox or listbox? I am inheriting a Combobox and want to validate items before they are added to the...
1
by: Mike | last post by:
Hi, I have a combobox bind to a datast.table and when tring to remove an Item from the combobox with this code: combobox.Items.RemoveAt(0) it's giving me this error "Cannot modify the Items...
1
by: Gian Paolo | last post by:
hi all i'm looking for a way to add 2 items in a combobox in the same line and hide one. i'm working on the code above but it returns me only the last value i entered and i do not know why.... ...
8
by: mironline | last post by:
dear friends I want to add and remove items with this simple code : private void comboBox1_KeyDown(object sender, KeyEventArgs e) { ComboBox c = sender as ComboBox; ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.