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

default value in a combo

Status
Not open for further replies.

sgueper

Programmer
May 2, 2002
18
ES

Sorry my english.

I don't know how to select a default value in a list or combobox. Can you help me?

Thanks
 
Code:
<SELECT Name="mySelect">
<option Value="One">One</Option>
<option Value="Two" SELECTED>Two</option>
<option value="Three">Three</option>
</SELECT>

"Two" will be the default. Hope that's what you meant.
 
Thanks a lot for your help, but the options are a recordset.

It is like this:

<option value="<%=RS2("Id")%>"><%=RS2("Activity")%></option>

and i don't know how to select one of them.

Thanks,
Silvia

 
<select name="whatever">
<%
Defaultvalue = whateveryouneedittobe
do while not RS2.EOF
If RS2("ID ? ACTIVITY") = DefaultValue Then
optSel = " SELECTED"
Else
optSel = ""
End If
%>
<option value="<%=RS2("Id")%>"<%=optSel%>><%=RS2("Activity")%></option>
<%
RS2.MoveNext
Loop
%>
</select>
 
Are you pulling the previously selected (saved) "ID" from the database before you populate the select?

Code:
<%
set conn=server.createobject("ADODB.CONNECTION")
conn.open yourConnectionString
strSql="SELECT * FROM myTABLE WHERE myCriteria=" & myCriteria
set rs=conn.execute(strSql)
If not rs.eof then
   'more variable assignments here
   mySelectID = rs("mySelectIDField")
End if
rs.close
set rs=nothing

' later on ...you build your SELECT from another recordset
' I'm leaving that stuff out
%>
<SELECT name="mySelect">
<%
do while not rs.eof
%>
<option value="<%=RS2("Id")%>" <%IF RS2("ID") = mySelectID THEN%>SELECTED<%End if%>><%=RS2("Activity")%></option>
<%
rs.movenext
loop
rs.close
set rs=nothing
%>
</SELECT>
Hope this helps.
 
In order to be xhtml compliant you'll need to do a

Code:
Response.Write("selected=""selected""")

instead of just "SELECTED"

Mike
 

Thank you very much. It is fantastic. today is hapier now.

Good day everybody.

Silvia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top