Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 7th, 2004, 06:14 PM
Authorized User
 
Join Date: Jun 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to remove an option from a list

Hi:

I'm looking to allow users to remove items from a select list, but I'm not certain how to go about that in Javascript. I know how to append items to a select list, but not to remove.

I'm guessing that it will involve returning the options array from the select list, looping through it until the item to delete is found, skipping it, and then running through the remaining items, so that they all move up on position in the index. But that still would seem to leave one extra item (blank) at the end of the list.

This technique would probably be the same as inserting a new option in a select list, as opposed to simply appending to it.


Thanks for your time,

JK
 
Old November 7th, 2004, 07:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

just set the value to null :

document.forms['testform'].testselect.options[i] = null;

see http://www.quirksmode.org/js/options.html
 
Old November 7th, 2004, 09:45 PM
Authorized User
 
Join Date: Jun 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Should've known. I keep looking for things like .addNew and .delete methods.

Thanks,
JK
 
Old November 8th, 2004, 08:06 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

John,
Do you want to delete the selectbox items by clicking the "Delete" button and Add New Items using "ADDNew" Button??


vinod
 
Old November 8th, 2004, 08:14 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

John ,
Hope this link help you
http://www.eddiesoft.com/eddiesoft/t...ls/entry2.html


vinod
 
Old November 9th, 2004, 11:09 PM
Authorized User
 
Join Date: Jun 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Vinod:

Thank you for the information, but Greg did answer my question. I may not have been clear enough when stating that in my response to Greg.

I really do appreciate your follow up.

Thanks,
JK





Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Check Boxes/Option buttons/Option Group hewstone999 Access VBA 1 March 14th, 2008 07:25 AM
Remove <select a value> option roy_mm Reporting Services 0 February 25th, 2007 02:26 AM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
Remove value of dropdown list when textbox changed sn00pyg4rfi3ld Javascript How-To 1 January 20th, 2005 07:08 AM
Remove entries in a list box rfinks Classic ASP Basics 1 October 15th, 2003 12:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.