Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing select box values into database

Status
Not open for further replies.

bren11

Programmer
Mar 14, 2002
21
US
Hi, everyone,

I have a form that is building select boxes using select statements to pull data from my access db.
However, this method is saving the values selected in the box as one whole string, (I have multiple columns).
I simply do not know how to separate the values from the query string using javascript so that I may save them to their proper fields in the database. I am so stuck on this one...any help or suggestions is appreciated...

Function BuildSelectControl(strName, strValue)

BuildSelectControl=""
Set rsTemp = server.CreateObject ("ADODB.Recordset")
strSQL =""
strSize = 1




if "ContactCode" = strName then strSize = 1 : strSQL = "SELECT [ContactCode]+[ContactName], [ContactCode]+[ContactName]FROM [CONTACTS] " end if

if "CustomerCode" = strName then strSize = 1 : strSQL = "SELECT [CustomerCode]+[CustomerName], [CustomerCode]+[CustomerName] FROM [CUSTOMERS] " end if



if strSQL <> "" then

rsTemp.open strSQL, dbConnection

if rsTemp.EOF then exit function
BuildSelectControl = BuildSelectControl & "<select size = " & strSize & " name=""" & strName & """>"
BuildSelectControl = BuildSelectControl & "<option value="""">Please select</option>"

while not rsTemp.Eof
if rsTemp(0)=strValue then
BuildSelectControl = BuildSelectControl & "<option value=""" & rsTemp(0) & """ selected>" & rsTemp(1) & "</option>"
else
BuildSelectControl = BuildSelectControl & "<option value=""" & rsTemp(0) & """>" & rsTemp(1) & "</option>"
end if
rsTemp.MoveNext
wend

BuildSelectControl = BuildSelectControl & "</select>"

rsTemp.Close
set rsTemp = Nothing
 

Select boxes, as far as I know, cannot display multiple columns of data. You can only display one column.

This means that:

1. You need to return only the data you want displayed, or
2. You need to re-think how you want to display all the data that is being displayed, or
3. You should store some of the data in an array (or hidden form fields), and some in the select box. This will let you keep all the data, but only display some.

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top