Skip to main content
Participant
Mar 7, 2007 4:10 PM UTC
Question

Selecting items in a list from a multivalue field

I have an edit page that includes a menu form element that allows multiple selections. It inserts all the IDs from a table that it's got from a recordset as a string into field named EventType separated by commas ("10000,10002,10004"). So far so good.

I have a dynamic menu behaviour on the edit page too but when I reload it none of the options in the list are selected. It will mark an item in the menu as selected when there's only one value, presumably because when there are multiples the behaviour is trying to match a string of "10000,10002,10004" to the values in the the list , which are separate values:

<select name="EventType" size="5" multiple="multiple" id="EventType">
<option value="10001" >Abseil</option>
<option value="10007" >Golf</option>
<option value="10000" >Marathon/Run</option>
<option value="10008" >Other outdoor</option>
<option value="10003" >Overseas</option>
<option value="10005" >Social</option>
<option value="10006" >Triathlon</option>
<option value="10004" >Walking</option>

I'd have thought this would have been dealt with by the behaviour, but apparently not. How to I break apart the multivalue field to select each item in the menu?
This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

Inspiring
Mar 7, 2007 4:40 PM UTC
Store the values in an array, then loop through the array to create the select options.
Translate
Participant
Mar 7, 2007 5:02 PM UTC
Thank you for poitning me in the right direction. I was being a little slow today:

While (NOT rsEventType.EOF)
%><option value="<%=(rsEventType.Fields.Item("ID").Value)%>" <%
Array = Split(rsEvent.Fields.Item("Type").Value,", ")
For Each i In Array
If rsEventType.Fields.Item("ID").Value = i Then
response.write "selected"
End If
Next
%>><%=(rsEventType.Fields.Item("EventType").Value)%></option>
<%
rsEventType.MoveNext()
Wend
Translate