Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I select a value from a drop-down?

Status
Not open for further replies.

Cineno

Programmer
Jul 24, 2006
142
US
Hello,

I have a form validation page that when a user clicks the button, if not all fields are selected, is redirected back to the page. I want the values they selected from the drop-down menus to still be there when they get back, so their choice is stored in a variable called "check3."

The select box's code is as follows:

<select name="ownership" SelectedIndex="<%check3%>">

<option value="">Select</option>
<option value="1">For Profit</option>
<option value="2">Not for Profit</option>
<option value="3">Government Owned</option>

</select>

I made sure "check3" has the correct value in it, but this is not working. Can anyone tell me what I should do?
 
put the selection in a session variable....something like this...

session("myselection") = request.form("ownership")

then...
Code:
<select name="ownership">
                  
<option value="" <%if session("myselection")="" then response.write "SELECTED" end if%>>Select</option>
<option value="1" <%if session("myselection")="1" then response.write "SELECTED" end if%>>For Profit</option>
<option value="2" <%if session("myselection")="2" then response.write "SELECTED" end if%>>Not for Profit</option>
<option value="3" <%if session("myselection")="3" then response.write "SELECTED" end if%>>Government Owned</option>
                      
</select>

-DNG
 
Thanks I'll try that. But there's no tag or anything I can use. I was writing this in Frontpage and the SelectedIndex came up as a property option. I'm just able to say "SelectedIndex = 2" or something?
 
Actually, no what you suggested is working fine. Thanks for the help!
 
Cineno said:
I was writing this in Frontpage and the SelectedIndex came up as a property option. I'm just able to say "SelectedIndex = 2" or something?

This is a good argument against using Frontpage, Dreamweaver, etc when trying to code ASP. Basically Frontpage made it up and probably put a whole bunch of inefficient logic in your code to manage it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top