473,402 Members | 2,046 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,402 software developers and data experts.

Remove an item from a select box

Rob

Hi,
I've got a small javascript problem and I'm kinda stuck. I'm using
classic ASP. I have a select box which is populated by a database query
and there is a buttom that when clicked it will move the selected item
from the first select box and move it to another select box:

document.form2.list.options[document.form2.list.options.length] = new
Option(count + 1 + ". " + name,company);

Then I want to remove it from the first select box:
document.form1.companies.options[document.form1.companies.selectedIndex]
.text = "";

But that just leaves an empty spot. I need to remove that spot
altogether and move all the other items up by one.
This is what I have:
for (i=document.form1.companies.options.length-1; i>0;
i--){document.form1.companies.options[document.form1.companies.selectedI
ndex].value = i;
}

But this doesn't work.
Anyone have any ideas?

Thanks

Rob

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
3 2330
Rob wrote:
Hi,
I've got a small javascript problem and I'm kinda stuck. I'm using
classic ASP. I have a select box which is populated by a database query
and there is a buttom that when clicked it will move the selected item
from the first select box and move it to another select box:

<snip>

Really Nice Code:

http://www.mattkruse.com/javascript/selectbox/

Mike
Jul 23 '05 #2
Rob
I know...I'm not big on Javascript.
Thanks for the code.

Rob

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
Rob wrote:
Hi,
I've got a small javascript problem and I'm kinda stuck. I'm using
classic ASP. I have a select box which is populated by a database query and there is a buttom that when clicked it will move the selected item from the first select box and move it to another select box:

document.form2.list.options[document.form2.list.options.length] = new
Option(count + 1 + ". " + name,company);

Then I want to remove it from the first select box:
document.form1.companies.options[document.form1.companies.selectedIndex] text = "";

But that just leaves an empty spot. I need to remove that spot
altogether and move all the other items up by one.
This is what I have:
for (i=document.form1.companies.options.length-1; i>0;
i--){document.form1.companies.options[document.form1.companies.selectedI ndex].value = i;
}

But this doesn't work.
Anyone have any ideas?

Thanks

Rob

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


<html>
<head>
<script type="text/javascript">

function delSelectedOpt(sel_id)
{
var o,
os,
len,
i = 0,
selobj = document.getElementById(sel_id);
if (selobj && (os = selobj.options))
{
while (o = os[i++])
if (o.selected)
{
for (len = os.length; i < len; ++i)
os[i - 1] = new Option(os[i].text, os[i].value);
os[--len] = null;
}
}
}

</script>
</head>
<body>
<form>
<select id="sss" size="8">
<option value="0">Option 0</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
<option value="6">Option 6</option>
<option value="7">Option 7</option>
</select>
<input type="button"
value="delete selected"
onclick="delSelectedOpt('sss')" />
</form>
</body>
</html>

Jul 23 '05 #4

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

Similar topics

2
by: Patrick G. | last post by:
Greetings all: ASP VB, SQL Svr 2000 I am pulling data from 3 tables. table1 holds item details table2 holds publication types and the item id from table1 table3 holds category types and...
8
by: Mikey | last post by:
I have an XML document as follows: <Menu> <Group> <Item Text="About Us" AccessRoles="All"> <Group> <Item Text="Option 1" AccessRoles="All" /> <Item Text="Option 2" AccessRoles="All" /> <Item...
4
by: u7djo | last post by:
Hi, I'm currently building an application in Access and as part of this need to import forms and modules from another database. Some of the imports will be revisions of existing forms/modules so I...
4
by: Ron | last post by:
I've got a listbox that holds a list of groups. Users can select a group, hit the remove button and the group should be removed from the listbox. The only problem is that no matter which group you...
1
by: deepak | last post by:
hi , i have 2 listbox and 2 buttons like add and remove, both listbox have multiple selection true so that i can either add or remove multiple selected items. the first listbox is populated with...
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...
3
by: Zorpiedoman | last post by:
Horay! I have just put the finishing touches on a new User Control... The" Jelly Button" I created a setup program which runs fine. I see the .dll nicely in the GAC. How come it does not...
3
by: Jeremy | last post by:
I'm trying to parse a sentence and want to remove selected words from the middle. Consider: dim a() as object = split(mySentence) for each w in a() select case w case w.startswith("X")
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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
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.