Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: RE: Adding and deleting options from select box on load


Message #1 by "Shashidhar Thoutireddy" <shashidhar.thoutireddy@w...> on Sat, 1 Feb 2003 12:37:50 +0530
The problem is that you weren't getting the selected values of FirstDay 
and LastDay correctly and you weren't using the correct names in the for 
loop.  Try this:

function setDays() {
      form = document.forms[0];
      topForm = window.parent.TopFrame.document.forms[0];
      var slct = topForm.WeekDay;

      FirstToAdd = form.FirstDay.options
[form.FirstDay.selectedIndex].value;
      LastToAdd = form.LastDay.options[form.LastDay.selectedIndex].value;

      deleteAllOptions();
      var optionElem = 0;
      for (n=FirstToAdd; n<=LastToAdd; n++) {
				OptToAdd = new Option(DaysOfWeek[n],n);
				slct.options[optionElem] = OptToAdd;
    		optionElem ++;
      }

}


> I think I've figured out my problem...  First of all, what I meant to 
type 
w> as OptToAdd = new Option(DaysOfWeek[n],n);
b> ut this still doesn't solve the problem.  I still get an error that it 
d> oesn't accept the property or method.  I think the problem is that I 
am 
u> sing a number in the Option() call instead of a string.  I don't 
u> nderstand why this is a problem, but all the examples I've seen use 2 
s> trings when creating a new Option.  Is there a way to get around this 
p> roblem, if in fact this is the problem?

  Return to Index