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

Combo box problem

Status
Not open for further replies.

uncgis

MIS
Apr 9, 2004
58
US
I have created a page called history.asp where users can add field values based on combo boxes...that page works great. Next I have created a page called EditHistory.asp, this page is used to edit the information. I want to be able to use combo boxes and preselect the same option that is already in the database. I have placed my code below..however, the select statement does not work.

<Select Name = "Circuit" Size = "1" value="<%=session("Circuit")%>">
<% Do While Not rs.EOF %>
<Option Value = <% =rs("CircuitID")%> Select <%=rsaddcomments("CircuitName")%> > <% =rs("CircuitName")%>
<% rs.MoveNext
Loop %>
</select>


Any help would be great...Thanks
 
Well, I'm not sure about the "Select" inside option tags.

Code:
<Select Name = "Circuit" Size = "1" value="<%=session("Circuit")%>">
<% 
Do While Not rs.EOF 
  Response.write "<Option Value='" & rs("CircuitID") & "'>" & rs("CircuitName") & "</option>"  
  rs.MoveNext  
Loop 
%>
</select>
 
Thanks for answering..

It does not give a an error...But it does not select the right option. For example, I would like for the combo box to select 'CROS' (the field value in the database from the History Table) but instead, it selects the first value from the Circuit Table ('Analog')

Hope this helps

Thanks
 
Here is what I usually do to populate a combo box:

Code:
<%
.
.
intValue [gray]'the value/ID of value stored in that record[/gray]

Dim strSelected
[gray]'lookupTable is a table with the full list of values you want in your listbox[/gray]
myRS.open strSQL_lookupTable, myConnection, 3, 1


strSelected = ""

do while not myRS.EOF
  if intValue = myRS("lookupID") then strSelected = " selected "
%>
...insert your HTML code here
<%
  strSelected = ""
  myRS.movenext
loop

Earnie Eng
 
To select the value you need, you can do something like

<%If rs("CircuitName")=theValue then%> selected <%end if%>
 
Thanks Kendel..That was the code I needed

<Select Name = "Circuit" Size = "1" value="<%=session("Circuit")%>">
<% Do While Not rs.EOF %>
<Option Value = <% =rs("CircuitID")%> <%if rs("CircuitName") = rsAddComments("CircuitName") Then %> selected <%End If%> > <% =rs("CircuitName")%>
<% rs.MoveNext
Loop %>
</select>

Thanks for everyone that answered
 
sorry for a partial answer above...
I was interruped when I hit the submit button..

yes.. Kendel's got the right idea with the if statment...

alternately, from my example above:
Code:
do while not myRS.EOF
  if intValue = myRS("lookupID") then strSelected = " selected "
%>
<option [b][blue]<%=strSelected%>[/blue][/b] ... the rest of your option HTML text>
<%
  strSelected = ""
  myRS.movenext
loop

I forgot to put that bit of code highlighted in blue on my previous post.

glad you got things working, though!

Earnie Eng
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top