473,809 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.create Element("form") ;

selectElem = document.create Element("select ");
selectElem.setA ttribute("name" , "video");
selectElem.setA ttribute("size" , "1");

form.appendChil d(selectElem);
...
}

else //empty existing one
{
while(???.optio ns.length) {
???.remove(0);
}
}
//ok now fill the newly created combobox or the existing one now
empty
for (var x in catalog)
{
optionElem = document.create Element('option ');
optionElem.setA ttribute('value ', i);

optionElemValue = document.create TextNode(x);
optionElem.appe ndChild(optionE lemValue)

selectElem.appe ndChild(optionE lem);
}

}
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 10536
On May 26, 7:00 pm, SM <servandomont.. .@gmail.comwrot e:
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.create Element("form") ;

selectElem = document.create Element("select ");
selectElem.setA ttribute("name" , "video");
selectElem.setA ttribute("size" , "1");

form.appendChil d(selectElem);
...
}

else //empty existing one
{
while(???.optio ns.length) {
???.remove(0);
}
Replace the above with:

} else {
selectElem.opti ons.length = 0;
}

//ok now fill the newly created combobox or the existing one now
empty
for (var x in catalog)
{
optionElem = document.create Element('option ');
optionElem.setA ttribute('value ', i);

optionElemValue = document.create TextNode(x);
optionElem.appe ndChild(optionE lemValue)

selectElem.appe ndChild(optionE lem);
Replace the above with:

selectElem.opti ons[selectElem.opti ons.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
2179
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 populated with a number of controls. This works fine for the first selection of a combobox item, but subsequent selections from the combobox cause problems. This is because the event function for the combobox populates the sizer for the window with...
3
7498
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 project, the combox box initially displays an empty selection. When I click on the drop down arrow I see the "Make a Selection" followed by the other choices. How can I move everything up so that the "Make a Selection" is the default value in...
0
2383
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 changed letter) because he reset the selectedindex of the combobox to -1. In debug mode I can't see where he does this. How can I solve this? My code sofar: contactlijst is a structure and the volgnummer is the index of the item in the combobox
3
3813
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 isn't working. It neither removes the item from the arraylist nor from the combobox like it's supposed to do. A couple of notes: cbx is the name of the combobox within my usercontrol, file is the name of the arraylist within my usercontrol. To try...
5
1777
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 one Sub with object as parameter? Here, my two Subs. Thanks Private Sub AnalyzeListBox()
9
7324
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 combobox, but I can't find anything that will let me do that. - Don
1
2248
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 collection when the DataSource property is set" -- Regads,
1
4721
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.... *********** CLASS using System; using System.Collections.Generic;
8
11699
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; if (c == null) return; if (c.Text == "") return; if (e.KeyCode == Keys.Delete)
0
9602
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10639
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.