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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing a select box from asp

Status
Not open for further replies.

smsinger3

Programmer
Oct 5, 2000
192
US
I have a web page with a select box. When the page runs for the first time, I want the select box to be positioned on the 4'th, 5'th or 6'th option depending on the user and other information. How can I write asp code to change the option before it goes to the browser?

Your help is certainly appreciated!

Steve S
sms@hmbnet.com
 
I believe I figured out my question. There is a statement called SELECT that will automatically select the option. The default is the first option, of course. Here is my asp code as an example:

<select name=&quot;Network&quot; length=&quot;20&quot;>
<option value=1 <%if strNetworkID = 1 then Response.Write &quot;SELECTED&quot;%>>Net1</option>
<option value=2 <%if strNetworkID = 2 then Response.Write &quot;SELECTED&quot;%>>Net2</option>
<option value=3 <%if strNetworkID = 3 then Response.Write &quot;SELECTED&quot;%>>Net3</option>
<option value=4 <%if strNetworkID = 4 then Response.Write &quot;SELECTED&quot;%>>Net4</option>
<option value=5 <%if strNetworkID = 5 then Response.Write &quot;SELECTED&quot;%>>Net5</option>
</select>

If you have a better way to this, then please post your code!

Steve S.
sms@hmbnet.com
 
I think I might have a cleaner way.

If you don't set a variable's value to start with, it is blank when you use it. So, technically all you would have to do is have code like this:

<SELECT NAME=&quot;test&quot;>
<option value=&quot;1&quot; <%=select1%>>Option 1</option>
<option value=&quot;2&quot; <%=select2%>>Option 2</option>
<option value=&quot;3&quot; <%=select3%>>Option 3</option>
<option value=&quot;4&quot; <%=select4%>>Option 4</option>
</SELECT>

Then, somewhere above this, just set whichever one you want to &quot;selected&quot;. So, if I wanted option 3 to start, I would just do (before you write the HTML)
<% select3 = &quot;selected&quot;%>

Since the others are blank by default, they will write nothing. The select3 will put the &quot;selected&quot; because you set its value. This way you don't have to check all four each time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top