Re: javascript select tag configuration

by "Hansen" <vhanse31(at)maine.edu>

 Date:  Fri, 3 Aug 2001 08:53:31 -0400
 To:  Paul Kmecak <pjkmecak(at)snet.net>
 Cc:  hwg-basics(at)hwg.org
 In-Reply-To: 
  todo: View Thread, Original
Hi Paul

Thank you so much for the suggestion.  It works great.

However, I have a question.  I'm getting a space before the list of 
numbers.  I can't seem to get rid of it.  Here's the script as it is now.

//remove the old list...............
removectr = (document.DateSelectionForm.dateout.options.length) -
 1;
while (removectr > -1) {
   document.DateSelectionForm.dateout.options[removectr]=null;
   removectr--;
}

//write the new list................
datectr = 0;
while (datectr <= numdays) {
  if (datectr == 1) {
    newdate = new Option(datectr, datectr, false, false);
    document.DateSelectionForm.dateout.options[datectr] = 
newdate;
    
document.DateSelectionForm.dateout.options[datectr].selected=tru
e;
  }
  else {
      newdate = new Option(datectr, datectr, false, false);
      document.DateSelectionForm.dateout.options[datectr] = 
newdate;
  }
  var dateoutlength = document.DateSelectionForm.dateout.length
  
  datectr++
 }
}


If datectr is set to 0, it puts 0 at the top of the list.  If it's set to 1, 
the numbers start at 1, but there's a blank space before 1.

I've tried decrementing the list length by 1 alternately before and 
after the loop runs, but this doesn't do it.  When it's after, it takes it 
off the end...so February ends up with only 27 days.  When I do it 
before, I get an out of memory error.

I just can't seem to wrap my sleep-deprived brain around this.  Do 
you know why this might be happening?

Victoria Hansen


On 31 Jul 2001, at 11:44, Hansen wrote:

> 
> ------- Forwarded message follows -------
> Date sent:      	Tue, 31 Jul 2001 11:20:53 -0400
> From:           	Paul Kmecak <pjkmecak(at)snet.net>
> Send reply to:  	pjkmecak(at)snet.net
> To:             	Hansen <vhanse31(at)maine.edu>
> Copies to:      	hwg-basics(at)hwg.org
> Subject:        	Re: javascript select tag configuration
> 
> Victoria,
> 
> The problem you're running into is caused by incrementing 
> removectr.
> Let's say you have a table
> 
> Element   Data
> 0             A
> 1             B
> 2             C
> 3             D
> 
> When you delete element 0 ("A"), B, C and D "shift down" to 
> become the
> data for elements 0, 1 and 2.  When you increment removectr from 0 to
> 1, you will delete "C", but leave "B" in place.
> 
> The simplest thing to do is clear the table from back to front.  Set
> removectr to document.DateSelectionForm.dateout.options.length -1. The
> "- 1" is important because arrays are 0 based - i.e., the subscripts
> for a 10 element array go from 0 to 9 and the length property is a
> count. For a 10 element array .length will return 10.
> 
> Then your code should look like
> 
> removectr = (document.DateSelectionForm.dateout.options.length) -1;
> while (removectr > -1) {
>   document.DateSelectionForm.dateout.options[removectr]=null;
>   removectr--;
> }
> 
> On the reload routine, you're initializing datectr to 1.  Again,
> arrays start at 0, not 1.  Try your script with these changes.  HTH.
> 
> Paul Kmecak
> 
> ------- End of forwarded message -------

HTML: hwg-basics mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.