We help IT Professionals succeed at work.
Get Started

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

ullenulle
ullenulle asked
on
336 Views
Last Modified: 2012-05-11
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
Comment
Watch Question
This problem has been solved!
Unlock 3 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE