473,511 Members | 14,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

insert item to dropdownlist using javascript

I can add items to my dropdown list using javascript like this:

cbo.length = j+2;

cbo.options[j].text = "Some Text";

cbo.options[j].value = "MyValue";

cbo.options[j+1].text = "Some Other Text";

cbo.options[j+1].value = "MyOtherValue";

But the above code adds them to the bottom of the list.

My question is how can add them back at a specific index in the list?
(I have a list of 10 items but remove two if they click an option button. If
they click back to the original value of the option group I want to add the
2 values back to the list. But in the right place.)

Any ideas?
--
Joe Fallon


Nov 19 '05 #1
2 13280
Joe,

First, remember the original index for the removed items.

Second, increment the ddl list by 2, as you do.

Third, move all options starting from the original position 2 positions up.
Do it in reverse order, starting from the highest position.

Forth, copy 2 removed item back to the original position.

Eliyahu

"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:eA*************@TK2MSFTNGP12.phx.gbl...
I can add items to my dropdown list using javascript like this:

cbo.length = j+2;

cbo.options[j].text = "Some Text";

cbo.options[j].value = "MyValue";

cbo.options[j+1].text = "Some Other Text";

cbo.options[j+1].value = "MyOtherValue";

But the above code adds them to the bottom of the list.

My question is how can add them back at a specific index in the list?
(I have a list of 10 items but remove two if they click an option button. If they click back to the original value of the option group I want to add the 2 values back to the list. But in the right place.)

Any ideas?
--
Joe Fallon

Nov 19 '05 #2
Elihayu,
Thanks for the tip.
I thought it might have to be something along those lines.

FYI - what I ended up doing was making a copy of the original list and then
using it to overwrite the modified list if they decided to change back. The
copy is only created once so they can toggle as many times as they want.
Seems to work fine.

Thanks again.
--
Joe Fallon


"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:uq**************@TK2MSFTNGP14.phx.gbl...
Joe,

First, remember the original index for the removed items.

Second, increment the ddl list by 2, as you do.

Third, move all options starting from the original position 2 positions
up.
Do it in reverse order, starting from the highest position.

Forth, copy 2 removed item back to the original position.

Eliyahu

"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:eA*************@TK2MSFTNGP12.phx.gbl...
I can add items to my dropdown list using javascript like this:

cbo.length = j+2;

cbo.options[j].text = "Some Text";

cbo.options[j].value = "MyValue";

cbo.options[j+1].text = "Some Other Text";

cbo.options[j+1].value = "MyOtherValue";

But the above code adds them to the bottom of the list.

My question is how can add them back at a specific index in the list?
(I have a list of 10 items but remove two if they click an option button.

If
they click back to the original value of the option group I want to add

the
2 values back to the list. But in the right place.)

Any ideas?
--
Joe Fallon


Nov 19 '05 #3

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

Similar topics

2
467
by: Antonio D'Ottavio | last post by:
Good Morning, In my web page I've a datalist that is sourced by a database, the problem is that I want that one of the column of the datalist contain a dropdownbox that also is sourced by a table...
7
4201
by: localhost | last post by:
A DataGrid with shows a label in one of the columns when in view mode. When in edit mode, I want to show a dropdown, and have the default selection set to what the textbox used to be. Right now...
3
26260
by: Stephen Adam | last post by:
Hi there, I'm sure i'm missing something really simple here, all i want to do is get the value of the selected item in a list box. Even after much fiddling about last night I still could not get...
3
2050
by: Sam C | last post by:
Hi, I have an ASP.Net page which has a DropDownList on it. The DDL is populated via a method which is called from the Page_Load if IsPostBack = False. When the form is submitted the...
15
3077
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
3
10561
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the...
5
5469
by: Me LK | last post by:
I need to add a line to choose a size into a dropdown . Since I have the dropdown nested inside a datagrid this is not working.When a page displays there are several rows of dropdowns but only the...
0
1273
by: myselfgautam.kumar | last post by:
I have three records into Database. Two of them are already displayed into datagrid.Third record which is a parameter , I have to select it from dropdownlist and then insert that record into grid...
5
3442
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration:...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
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
7349
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,...
1
7074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
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
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
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 ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
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...

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.