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 August 13th, 2004, 10:55 PM
Authorized User
 
Join Date: Jul 2003
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to remove all elements of select in JavaScript

I have a select type element,like follows:
<select size="8" name="selUser" style="width:250" multiple>
<option name="1" value="1">1</option>
.....
<option name="5" value="5">5</option>
</option>
<input type="button" name="del" onclick="delall()">

I want to realize this function: when click button,the content of select is all removed.
How to realize this function?

Thanks in advance!

 
Old August 14th, 2004, 05:11 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Code:
document.forms[0].selUser.options.length = 0;
You can modify the reference to use the name of the form if it's not the first one.



--

Joe





Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove orphaned html elements from html string pauliehaha C# 2008 aka C# 3.0 2 June 30th, 2008 09:40 AM
remove empty elements but not ones with attributes dupdup XSLT 1 March 3rd, 2007 07:02 PM
Remove <select a value> option roy_mm Reporting Services 0 February 25th, 2007 02:26 AM
adding option elements dynamically to a select richard.york Javascript 4 December 5th, 2003 04:57 AM
Select distinct elements andrin XSLT 2 August 4th, 2003 04:07 AM





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