Forums

ASP

This topic is locked

Multiple Select List - Setting Value Equal To

Posted 02 Feb 2003 22:19:19
1
has voted
02 Feb 2003 22:19:19 Chris Rowe posted:
I have a multiple select list where users can pick more than one item to be stored in the database (product colors i.e. "blue,red,green,black". My question is how do you set the value equal to that string ("blue,red,green,black" when the user wants to edit which colors are available for that product?

============================================

Here's my Multiple select list:


<select name="ProdColor" size="4" multiple id="ProdColor" style="FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 7.1pt; FONT-WEIGHT: normal">
<%
While (NOT rsColors.EOF)
%>
<option value="<%=(rsColors.Fields.Item("ColorValue".Value)%>" <%If (Not isNull((rsNavBarEdit.Fields.Item("ProdColor".Value))) Then If (CStr(rsColors.Fields.Item("ColorValue".Value) = CStr((rsNavBarEdit.Fields.Item("ProdColor".Value))) Then Response.Write("SELECTED" : Response.Write(""%> ><%=(rsColors.Fields.Item("ColorName".Value)%></option>
<%
rsColors.MoveNext()
Wend
If (rsColors.CursorType > 0) Then
rsColors.MoveFirst
Else
rsColors.Requery
End If
%>
</select>



==========================================


Thanks for the help.

Replies

Replied 18 Feb 2003 01:29:36
18 Feb 2003 01:29:36 Chris Rowe replied:
Ok, I have been banging my head against the wall trying to figure this out. Here's my latest version and it still doesn't work. It will work with one value. Someone please help!!!

<select name="ProdColor" size="10" multiple>
<%
While (NOT rsColors.EOF)
colorList = CStr(rsColors.Fields.Item("ColorValue".Value)
%>
<option value="<%=colorList%>"
<%
rsNavBarEdit.MoveFirst()
%>
<%
While (NOT rsNavBarEdit.EOF)
If (CStr(rsNavBarEdit.Fields.Item("ProdColor".Value) = colorList) Then Response.Write("SELECTED"
rsNavBarEdit.MoveNext()
Wend
%>><%=(rsColors("ColorName")%></option>
<%
rsColors.MoveNext()
Wend
%>
</select>
Replied 19 Feb 2003 17:54:39
19 Feb 2003 17:54:39 Erik Mr. replied:
I just recently solved this for my particular situation. Cannot use Dreamweaver generated listbox, But can use the recordsets. Follow comments on replacing. You'll have to play with the code based on how you have your listbox recordset associated with the user recordset. Good Luck!


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

Reply to this topic