Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Remove multiple items from listbox in Javascript [Chatakondu Gallery]

Reply
Thread Tools

Remove multiple items from listbox in Javascript [Chatakondu Gallery]

 
 
Suresh
Guest
Posts: n/a
 
      04-16-2004
formName: Name of the form
ctrlListBox: Name of the Listbox control

function fnRemoveListItem(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.elements.length;i++)
{
var e = obj.elements[i];
var elementName = e.name.toString()
if (elementName.indexOf(ctrlListBox) >= 0 )
{
var objctrlListBox = e;
break;
}
}
for (var i = 0; i < objctrlListBox.length; i++)
{
if (objctrlListBox.options[i].selected)
{
objctrlListBox.remove(objctrlListBox.selectedIndex );
i--;
}
}
return;
}
}
 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      04-16-2004
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox move multiple selected items to second listbox K B ASP .Net 2 01-08-2007 11:16 AM
Urgent!!!!! Remove Items from a <Asp:Listbox> thru javascript =?Utf-8?B?U2lsZWVzaA==?= ASP .Net 2 11-04-2004 08:13 PM
How do I move all items in a listbox to another listbox kent ASP .Net 1 05-03-2004 12:17 AM
add items from one listbox to other listbox from javascript mc Javascript 0 12-02-2003 08:23 PM
Remove multiple selected items listbox Adrian Forbes ASP General 0 08-07-2003 03:19 PM



Advertisments