Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Preselect dropdown in HTML form from mqsql database

Options
  • 12-12-2008 10:50am
    #1
    Registered Users Posts: 7,405 ✭✭✭


    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 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