Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Preselect dropdown in HTML form from mqsql database

  • 12-12-2008 10:50AM
    #1
    Registered Users, Registered Users 2 Posts: 7,462 ✭✭✭


    How do I preselect an item in an HTML form dropdown(select) pulling data from a mysql database scripting in ASP?

    Here's what I have so far
    <SELECT name=""yesOrNo""><OPTION value =" & Recordset("yesOrNo") &" SELECTED>" & Recordset("yesOrNo") &"</OPTION><OPTION value =""YES"">YES</OPTION><OPTION value =""NO"">NO</OPTION></SELECT>

    It does correctly pull the selected one from the database but Yes and No always appear in the dropdown along with the preselected one. So if yes is selected, then in the dropdown will appear, Yes Yes No


Comments

  • Registered Users, Registered Users 2 Posts: 177 ✭✭mercuroman


    I think you'll have to handle this in the some client side script.
    Something like this:

    yesorno = yesorno & "<OPTION value =" & Recordset("yesOrNo") &" SELECTED>" & Recordset("yesOrNo") &"</OPTION>"
    if Recordset("yesOrNo") = "YES" then
    yesorno = yesorno & "<OPTION value =""NO"">NO</OPTION>"
    else
    yesorno = yesorno & "<OPTION value =""YES"">YES</OPTION>"
    end if

    Then in the HTML:
    <SELECT name=""yesOrNo""><%=yesorno%></SELECT>


Advertisement