Link to home
Create AccountLog in
Avatar of ullenulle
ullenulleFlag for United States of America

asked on

Preselect a value in a dropdownmenu based on a query-string.

Hi there.

I have a SELECT-menu that pulls values from a MySQL-database. I want this particular menu to be populated with a query-string. So far I just added another OPTION VALUE-line, but that's kinda "cheat", since the query-value will be there twice. Any suggestions how to do it more correctly? :-)
Here's my code so far:

<select name="samarbejdspartner_expense" id="samarbejdspartner_expense" onChange="reload()">
     <option value="null" <%If (Not isNull((Recordset1.Fields.Item("samarbejdspartner_expense").Value))) Then If ("null" = CStr((Recordset1.Fields.Item("samarbejdspartner_expense").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>></option>
     <option value="Request.QueryString("partner")" <%If (Not isNull(Request.QueryString("partner"))) Then If (Request.QueryString("partner") = CStr(Request.QueryString("partner"))) Then Response.Write("selected=""selected""") : Response.Write("")%>><%=(Request.QueryString("partner"))%></option>
     <%
While (NOT Recordset3.EOF)
%>
     <option value="<%=(Recordset3.Fields.Item("partner_navn").Value)%>" <%If (Not isNull((Recordset1.Fields.Item("samarbejdspartner_expense").Value))) Then If (CStr(Recordset3.Fields.Item("partner_navn").Value) = CStr((Recordset1.Fields.Item("samarbejdspartner_expense").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%> ><%=(Recordset3.Fields.Item("partner_navn").Value)%></option>
     <%
  Recordset3.MoveNext()
Wend
If (Recordset3.CursorType > 0) Then
  Recordset3.MoveFirst
Else
  Recordset3.Requery
End If
%>
   </select>

Open in new window


Best regards

Ullenulle
SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of ullenulle

ASKER

I found out the solution on my own... but thanks for your attention. :-)