Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms 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 10th, 2005, 08:45 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select a Item In Drop-Down List

Hi All,

I created a form(userInput.asp) where users can select from a drop-down menu. The values in the menu are:

<select name="sport">
    <option value="1">Baseball</option>
    <option value="2">Basketball</option>
    <option value="3">Tennis</option>
</select>

Let say a user selected basketball, and submitted the form. The data go into a database.

Here is what I want to do. Search(EditUserInput.asp) for this user, and be able to see his selection in a dropdown menu. Here is the key, I want his selection as the "selected default."

In other words, after I searched for this person and view his record, there is a dropdown menu with three selections(Baseball, Basketball, Tennis), but with "Basketball" hightlighted. Make sense?

Thank you for your help.

Leon

 
Old March 11th, 2005, 12:47 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

You can make the items as selected by checking in the if condition and make it as selected.
if(strOptionValue =="Baseball")
   <option value="1" selected>Baseball</option>
end if


 
Old March 11th, 2005, 11:53 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks for the advise, but I am afraid my problem is more difficult than that. You see, I have a dropdown list of 20 items(basketball, tennis, football, hocky, etc..). There will be pages of code if I do an "If" statement that way. Is there an easier way?

Thanks.

Leon

 
Old March 11th, 2005, 12:42 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Nevermind about my question. I have figured it out. Thanks again!

Leon

 
Old March 14th, 2005, 02:52 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

If you are hardcoding the values in the dropdownlist then you have to do 20 ifs.
  Populate the values for the dropdownlist from the database and if the submitted value matches the dropdownlist value from the database make the option as selected else not selected.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the first item of a List hpox ASP.NET 2.0 Basics 1 February 16th, 2007 06:04 PM
problem in selecting the item from drop down list swati_joshi ASP.NET 1.0 and 1.1 Basics 1 March 27th, 2006 01:24 AM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
select a default value in a drop-down list crmpicco HTML Code Clinic 2 January 20th, 2005 08:23 AM





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