Forums
This topic is locked
URGENT - ASP Multi-select list in Update form
13 Feb 2003 17:24:42 Erik Mr. posted:
Many are able to create a multiselection list in Dreamweaver that will allow users to submit data into access, something like A,B,C. The problem with dynamically reading those values back into the same multi-select list for an update form is puzzling me, Macromedia tech and other users in this forum. We can all read a value of (A) back into the multi select form list and have it appear selected, but if we try to read in (A, B) we have no luck using Dreamweaver generated code.PLEASE...if anyone has resolved this...here is part of my current code.
******* SUBSCRIBER RECORDSET **********
<%
Dim Subscribers__MMColParam
Subscribers__MMColParam = "1"
If (Request.QueryString("email" <> "" Then
Subscribers__MMColParam = Request.QueryString("email"
End If
%>
<%
Dim Subscribers
Dim Subscribers_numRows
Set Subscribers = Server.CreateObject("ADODB.Recordset"
Subscribers.ActiveConnection = MM_business_opps_STRING
Subscribers.Source = "SELECT * FROM contacts WHERE email = '" + Replace(Subscribers__MMColParam, "'", "''" + "'"
Subscribers.CursorType = 0
Subscribers.CursorLocation = 2
Subscribers.LockType = 1
Subscribers.Open()
Subscribers_numRows = 0
%>
****** DYNAMIC LIST RECORDSET *******
<%
Dim Bio__MMColParam
Bio__MMColParam = "I-"
If (Request("MM_EmptyValue" <> "" Then
Bio__MMColParam = Request("MM_EmptyValue"
End If
%>
<%
Dim Bio
Dim Bio_numRows
Set Bio = Server.CreateObject("ADODB.Recordset"
Bio.ActiveConnection = MM_business_opps_STRING
Bio.Source = "SELECT * FROM codes WHERE TypeCode LIKE '" + Replace(Bio__MMColParam, "'", "''" + "%' ORDER BY TypeCode ASC"
Bio.CursorType = 0
Bio.CursorLocation = 2
Bio.LockType = 1
Bio.Open()
Bio_numRows = 0
%>
'*******PART OF CODE THAT POPULATES MULTI-SELECT LIST WITH LABELS AND VALUES FROM BIO RECORDSET *** THEN IS SUPPOSED TO DISPLAY SELECTED ITEMS A AND B FROM COMMA SEPARATED DATA IN SELECTED OPPS FIELD IN THE SUBSCRIBERS RECORDSET (A, B, ). IT ONLY DISPLAYS IF VALUE IS A OR B BUT NOT (A, B) ******************************
*********FIELD SELECTED_OPPS IS AN ARRAY OF USERS SELECTED TYPECODES IN MULTI SELECT LIST ************************
<select name="selected_opps" size="10" multiple id="selected_opps3">
<%
While (NOT Bio.EOF)
%>
<option value="<%=(Bio.Fields.Item("TypeCode".Value)%>" <%If (Not isNull((Subscribers.Fields.Item("selected_opps".Value))) Then If (CStr(Bio.Fields.Item("TypeCode".Value) = CStr((Subscribers.Fields.Item("selected_opps".Value))) Then Response.Write("SELECTED" : Response.Write(""%> ><%=(Bio.Fields.Item("Explanation".Value)%></option>
<%
Bio.MoveNext()
Wend
If (Bio.CursorType > 0) Then
Bio.MoveFirst
Else
Bio.Requery
End If
%>
</select>
Replies
Replied 19 Feb 2003 18:10:02
19 Feb 2003 18:10:02 Erik Mr. replied:
Much research... Here's the answer.
'*******PLACE BELOW CODE AFTER RECORDSETS AND BEFORE <HTML> *********
' YOU NEED TO REPLACE "Subscribers.Fields.Item("selected_opps".Value" with your user's selected colors recordset comma separated field
<% 'START OF CODE NEED FOR MULTISELECT LISTBOX TO WORK WITH DREAMWEAVERMX RECORDSETS
dim strClean, strClean2, StrClean3 'CLEAN UP ACCESS SELECTED VALUES ARRAYS (A, B, C,)
strClean = Subscribers.Fields.Item("selected_opps".Value
strClean = Replace(strclean, ", ", ","
' END OF DREAMWEAVERMX SELECTED VALUES CLEANING OF COMMA SEPARATED VALUES %>
'*******PLACE ABOVE CODE AFTER RECORDSETS AND BEFORE <HTML> *********
'*******PLACE BELOW CODE Where YOU WANT YOUR LISTBOX *********
<% ' CREATE ARRAYS OF VALUES FOR MULTI SELECTBOX LISTBOX LABELS AND ASSOCIATED VALUES
While (NOT Bio.EOF)
dim strType1 ' TypeCode Values in array
dim strExp1 ' Label Values in array
' Replace Bio.Fields.Item("TypeCode".Value with your color naming recordset value
strType1 = strType1 & Bio.Fields.Item("TypeCode".Value & ","
' Replace Bio.Fields.Item("Explanation".Value with your color naming recordset Label
strExp1 = strExp1 & Bio.Fields.Item("Explanation".Value & "," ' Label Values in array
Bio.MoveNext() ' replace Bio. with recordset for naming colors rsColors. ?
Wend
If (Bio.CursorType > 0) Then
Bio.MoveFirst
Else
Bio.Requery
End If
%>
<% ' MANIPULATE ARRAYS FROM PREVIOUS STEP TO WRITE MULTISELECT LISTBOX WITH SELECTED VALUES FROM ACCESS DATABASE COMMA SEPARATED VALUE
strSelection = strClean '"x,y,z" '* LIST OF RECORDED USER SELECTIONS FROM ACCESS IN CLEANED ARRAY
strSelection = "," & strSelection & "," '"," & strSelection & ","
strFull = strType1'"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" COMPLETE LIST OF POSSIBLE VALUES IN CREATED ARRAY
Dim arrFull, intEntry, strSelected
arrFull = split(strFull, "," 'Values
arrFull2 = split(strEXP1, "," 'Labels
%>
<select name="ProdColor" size="4" multiple id="ProdColor" style="FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 7.1pt; FONT-WEIGHT: normal">
<%
For intEntry = lBound(arrFull) To uBound(arrFull)
if instr(strSelection,"," & arrFull(intEntry) & "," > 0 then
strSelected = "selected"
else
strSelected = ""
end if
%>
<option value=""<%=arrFull(intEntry)%>"" <%=strSelected%>><%=arrFull2(intEntry)%></option>
<%
Next
%>
</SELECT>
'*******PLACE BELOW CODE AFTER RECORDSETS AND BEFORE <HTML> *********
' YOU NEED TO REPLACE "Subscribers.Fields.Item("selected_opps".Value" with your user's selected colors recordset comma separated field
<% 'START OF CODE NEED FOR MULTISELECT LISTBOX TO WORK WITH DREAMWEAVERMX RECORDSETS
dim strClean, strClean2, StrClean3 'CLEAN UP ACCESS SELECTED VALUES ARRAYS (A, B, C,)
strClean = Subscribers.Fields.Item("selected_opps".Value
strClean = Replace(strclean, ", ", ","
' END OF DREAMWEAVERMX SELECTED VALUES CLEANING OF COMMA SEPARATED VALUES %>
'*******PLACE ABOVE CODE AFTER RECORDSETS AND BEFORE <HTML> *********
'*******PLACE BELOW CODE Where YOU WANT YOUR LISTBOX *********
<% ' CREATE ARRAYS OF VALUES FOR MULTI SELECTBOX LISTBOX LABELS AND ASSOCIATED VALUES
While (NOT Bio.EOF)
dim strType1 ' TypeCode Values in array
dim strExp1 ' Label Values in array
' Replace Bio.Fields.Item("TypeCode".Value with your color naming recordset value
strType1 = strType1 & Bio.Fields.Item("TypeCode".Value & ","
' Replace Bio.Fields.Item("Explanation".Value with your color naming recordset Label
strExp1 = strExp1 & Bio.Fields.Item("Explanation".Value & "," ' Label Values in array
Bio.MoveNext() ' replace Bio. with recordset for naming colors rsColors. ?
Wend
If (Bio.CursorType > 0) Then
Bio.MoveFirst
Else
Bio.Requery
End If
%>
<% ' MANIPULATE ARRAYS FROM PREVIOUS STEP TO WRITE MULTISELECT LISTBOX WITH SELECTED VALUES FROM ACCESS DATABASE COMMA SEPARATED VALUE
strSelection = strClean '"x,y,z" '* LIST OF RECORDED USER SELECTIONS FROM ACCESS IN CLEANED ARRAY
strSelection = "," & strSelection & "," '"," & strSelection & ","
strFull = strType1'"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" COMPLETE LIST OF POSSIBLE VALUES IN CREATED ARRAY
Dim arrFull, intEntry, strSelected
arrFull = split(strFull, "," 'Values
arrFull2 = split(strEXP1, "," 'Labels
%>
<select name="ProdColor" size="4" multiple id="ProdColor" style="FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 7.1pt; FONT-WEIGHT: normal">
<%
For intEntry = lBound(arrFull) To uBound(arrFull)
if instr(strSelection,"," & arrFull(intEntry) & "," > 0 then
strSelected = "selected"
else
strSelected = ""
end if
%>
<option value=""<%=arrFull(intEntry)%>"" <%=strSelected%>><%=arrFull2(intEntry)%></option>
<%
Next
%>
</SELECT>
Replied 05 Dec 2006 12:01:35
05 Dec 2006 12:01:35 Iain wood replied:
Hi there
found a quick fix for those who really don't need total accuracy (it's ok for simple lists)
use the good old Instr() command to check the list in stead of the = option for the selected bit
If (Not isNull(request.form("listme")) Then If instr(CStr(request.form("listme"),CStr(Recordset1.Fields.Item("Product_code".Value))
I found that this did a simple quick fix if you want to keep a the options selected (It's not going to work for everything so dont complain if it gives you duff results)
found a quick fix for those who really don't need total accuracy (it's ok for simple lists)
use the good old Instr() command to check the list in stead of the = option for the selected bit
If (Not isNull(request.form("listme")) Then If instr(CStr(request.form("listme"),CStr(Recordset1.Fields.Item("Product_code".Value))
I found that this did a simple quick fix if you want to keep a the options selected (It's not going to work for everything so dont complain if it gives you duff results)