Jump to content
Sign in to follow this  
csarafin

using selected option from combobox in SQL to get specific row from database

Recommended Posts

I'm new to ASP and have a form that lets users choose a division code from a dropdown box that is populated from an access database. Once they have selected the division, I'd like to be able to collect other fields (name, address, city, state, zip) from that same recordset and pass those fields to another asp page. I'm able to write the selected code to the database, but can't figure out how to collect the other fields from that specific line in the table. My code is

 

 

<%Set objconn = Server.CreateObject("ADODB.Connection")objconn.ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("data/jobdata.mdb")objconn.OpenSet objRs = Server.CreateObject("ADODB.Recordset")strSQL = "SELECT * FROM Locations "objRs.Open strSQL, objconnResponse.Write "<select name=DCode><option value='' selected></option>"Do While Not objRS.EOFResponse.Write "<option value='" & objrs("DCode") &"'>"& objRs("DCity") &"</option>"objRS.MoveNextLoopResponse.Write "</select>"objRs.Closeobjconn.Close%>How do I get the page to also get the DName, DAddress1, DAddress2, DCity, DState, and DZIP fields from the selected DCode so it can be passed to another page for display or writing to a different database.Thanks much, csarafin

Share this post


Link to post
Share on other sites

If you want to do that without the page refreshing then you'll need to use Javascript. There are several options, one of them is to send an ajax request when they select a division to get the rest of the data, or another option is to write all of the data out when you're going through the recordset. You could write that data into something like a Javascript array and look it up there when they choose a division, or use data attributes on the option elements and look it up there.

Share this post


Link to post
Share on other sites

I like the idea of using data attributes on the option elements. How would I extract all this data on the next page so each attribute would be written to a separate column in a table in a different database?

 

Thanks,

csarafin

Share this post


Link to post
Share on other sites

Data attributes won't get sent along with the form data, so you would need a Javascript function that would run when they change the selection and do something like copy the various data attributes into hidden form fields that will be included when the form is submitted.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...