473,811 Members | 2,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remove multiple items from listbox in Javascript [Chatakondu Gallery]

formName: Name of the form
ctrlListBox: Name of the Listbox control

function fnRemoveListIte m(formName, ctrlListBox)
{
if (formName == '')
var formName = document.forms( 0).name
obj = eval("document. " + formName)

if (confirm("Are you sure you want to remove this item?"))
{
for (var i=0;i<obj.eleme nts.length;i++)
{
var e = obj.elements[i];
var elementName = e.name.toString ()
if (elementName.in dexOf(ctrlListB ox) >= 0 )
{
var objctrlListBox = e;
break;
}
}
for (var i = 0; i < objctrlListBox. length; i++)
{
if (objctrlListBox .options[i].selected)
{
objctrlListBox. remove(objctrlL istBox.selected Index);
i--;
}
}
return;
}
}
Jul 23 '05 #1
1 11934
Suresh wrote:
<snip>
if (formName == '')
var formName = document.forms( 0).name ^ ^
Very few browsers understand parenthesise used in a property accessor
context. They all understand bracket notation when used for the task.
obj = eval("document. " + formName)

<snip>

The use of - eval - is always unnecessary with property accessors. See:-

<URL: http://jibbering.com/faq/#FAQ4_39 >

The logic of the preceding 3 lines could be written as:-

obj = document.forms[(formName || 0)];

Incidentally, posting tab indented code on Usenet is counter productive
as some newsreaders collapse tabs completely (removing indentation),
while others will use default numbers of spaces per tab that are to
large for reasonable code presentation. Instead tabs should be converted
to a suitable number of spaces prior to positing. It is all covered in
the group's FAQ.

Richard.
Jul 23 '05 #2

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

Similar topics

3
19574
by: darren | last post by:
How, using asp.net (vb.net), can I remove multiple selected items from a listbox. Everything I try does not seem to work. Thanks in advance.
2
1453
by: Suresh | last post by:
formName: Form name controlCheckAll: check all checkbox (parent) control name controlCheckOne: child checkbox control name // To check and uncheck all check boxes. Form name is optional. function fnCheckUnCheckAllCheckBoxes(formName, controlCheckAll, controlCheckOne) { if (formName == '') var formName = document.forms(0).name obj = eval("document." + formName)
1
1645
by: NiLaY | last post by:
I have a function like the one below to move a selected option from one listbox to another. But I want to be able to select multiple and be able to move those selections to the other listbox. Can anyone help me on that. Thank you <html> <head> <script language="JavaScript"> function addOption(sBox, aBox) {
3
22565
by: ted | last post by:
Hi, I can't figure out how to set multiple items in a ListBox to selected when the listbox is in a User Control. When the ListBox is set in directly into a form I can use the following: listbox.SelectionMode = SelectionMode.MultiExtended; listbox.SelectedIndex = 1; listbox.SelectedIndex = 2;
4
11500
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 select, the first one in the listbox is always removed.(The listitem with an index of 0. Box is set to single selection mode) I've looked at multiple examples and they all do it this way. What's wrong? (variables are also being set to the values...
1
5882
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 sql server table during page load time and the second one is empty, now i want if a user select item/s in first listbox then it should add in another listbox after clicking add withour postback using javascript and the item's text which is...
0
1470
by: deepak | last post by:
i have set multiple selection property in bith listboxes(html control) to true. i have taken 2 buttons(html control) say Button1,Button2.now i want to add mutiple selected items to another listbox after clicking button1, and similray remvoing the mutiple selected ite,s from, another after clicking button2 ,, how can i do this ,, my script is given belo...
1
2249
by: sab | last post by:
Hi, We have a web form with a listbox. The listbox is a multiple select listbox and has data that looks something like: ALL Unit 1 Unit 2 Unit 3 Note: "ALL" is always the first item in the list.
10
3695
by: kimiraikkonen | last post by:
Hi, I have an app which has a listbox and when i double click an associated fileS, i want their paths to be added into listbox in my application. This code works good when i try to open a "single" file with my app which works to get commandline arguments to get file paths: Dim cla As String() = Environment.GetCommandLineArgs() If cla.Length 1 Then
0
9605
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
10651
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
10392
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10136
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
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...
1
7671
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5555
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...
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
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.