View Full Version : Dynamically changing a list box ?

Nov 30th, 2002, 09:38 PM
I have a list box of calendar months that changes, depending upon the user's selection in the language list box. For example, if he chooses German instead of English, the code looks like :

MonthsList.options[12] = new Option ("Dezember")

Question is, how do I make this the "selected" item in the list box?

I've tried doing :

MonthsList.options[12] = new Option Selected ("Dezember") but it blows up.

Nov 30th, 2002, 09:40 PM
document.formname.MonthsList.options[10] = new Option ("Oktober")
document.formname.Monthslist.options[10].selected = 1 //or true

Nov 30th, 2002, 09:53 PM
Thanks, works like a charm ! Now all I have to do is get the current month and put a "ternary" operator in there like :

month = current_month ? : statement one : statement two

That way, the current month will always be selected.

I think JS supports the "?" operator, right ?

Nov 30th, 2002, 10:00 PM
the ? and : can be used in place of if and else commands.