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 March 18th, 2005, 11:56 AM
Friend of Wrox
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select box for loop(probably really simple)


I am trying to get a select box to reset all its options to null. This is my code:

var theoptions = document.form2.dateselect.options

for (i = theoptions.length; i < 5; i++){

theoptions[i]= null;

I notice that the length of a select box will return 0, so I might be wasting my time calling it, but since it returns 0 every time I figure thats a solid starting point for the for loop. This method of setting each option to null by putting [i] in there doesn't seem to do anything. Any ideas?


\'sync\' &lt;cr&gt;
The name specified is not recognized as an internal or external command, operable program or batch file.
Old March 18th, 2005, 12:18 PM
Friend of Wrox
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts

Doh! It was really simple!

var theoptions = document.form2.dateselect.options
for (i = 0; i < 5; i++){
theoptions[0]= null;

Of course! The index shifts, so its always 0!


Old March 18th, 2005, 12:25 PM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

document.form2.dateselect.options.length = 0;

Joe (Microsoft MVP - XML)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Nesting Loop PommyTom XSLT 2 June 9th, 2006 02:16 AM
Fill select box and select recordset value markd Classic ASP Databases 1 February 20th, 2006 06:41 PM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM
Nested Loop Select Box Issue mat41 Classic ASP Basics 5 August 24th, 2004 11:02 PM
simple loop question Adam H-W Classic ASP Basics 2 July 9th, 2004 01:22 AM

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