Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Preselect dropdown in HTML form from mqsql database

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


    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
Advertisement