Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Selecting DropDownList Items Programatically


Message #1 by "Hugh McLaughlin" <hugh@k...> on Sat, 13 Jul 2002 03:22:31
Hello Everyone and thanks for your help in advance.  I am working on a web 
form that allows the user to select a month from a dropdownlist (i.e. 
January, February, etc.).  I want to set the initial value of the 
DropdownList to the current month.  How do I do this?  Since I have 
already coded in all of the months, will the selected item appear twice?  
I ahve also done something similar for the year, but programatically start 
with the current year minus 5 to current year plus 10, using 
add.listitem.  Again, what is the easiest way to do this?  any help would 
be greatly appreciated.  Thanks.
Message #2 by kyle.b.willman@u... on Mon, 15 Jul 2002 06:40:07 -0500
In order to set the selected option on a <SELECT> item, you need to:

      <SELECT ... >
      <% If Month(Date) = "January" then %>
            <OPTION VALUE="January" SELECTED>January</OPTION>
      <% Else %>
            <OPTION VALUE="January">January</OPTION>
      <% End if %>
      ...
      </SELECT>

This should do it.  If you are looping, do the same thing substituting your
loop variables.

Kyle B. Willman
PricewaterhouseCoopers LLP
Office:  xxx.xxx.xxxx
Cell:   xxx.xxx.xxxx


                                                                                                                                    
                      "Hugh McLaughlin"                                                                                             
                      <hugh@k...       To: "ASP Web HowTo" <asp_web_howto@p...>                            
                      om>                      cc:                                                                               
                      07/12/2002 10:22         Subject:  [asp_web_howto] Selecting DropDownList Items Programatically               
                      PM                                                                                                            
                                                                                                                                    
                      Please respond to                                                                                             
                      "ASP Web HowTo"                                                                                               
                                                                                                                                    
                                                                                                                                    




Hello Everyone and thanks for your help in advance.  I am working on a web
form that allows the user to select a month from a dropdownlist (i.e.
January, February, etc.).  I want to set the initial value of the
DropdownList to the current month.  How do I do this?  Since I have
already coded in all of the months, will the selected item appear twice?
I ahve also done something similar for the year, but programatically start
with the current year minus 5 to current year plus 10, using
add.listitem.  Again, what is the easiest way to do this?  any help would
be greatly appreciated.  Thanks.

---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20




_________________________________________________________________
         The information transmitted is intended only for the person or
         entity to which it is addressed and may contain confidential
         and/or privileged material.  Any review, retransmission,
         dissemination or other use of, or taking of any action in reliance
         upon, this information by persons or entities other than the
         intended recipient is prohibited.   If you received this in error,
         please contact the sender and delete the material from any
         computer.


  Return to Index