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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Preselect dropdown in HTML form from mqsql database

  • 12-12-2008 9:50am
    #1
    Registered Users, Registered Users 2 Posts: 7,423 ✭✭✭


    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