Skip to main content
Participant
March 7, 2007
Question

Selecting items in a list from a multivalue field

  • March 7, 2007
  • 1 reply
  • 240 views
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 has been closed for replies.

1 reply

Inspiring
March 7, 2007
Store the values in an array, then loop through the array to create the select options.
Participant
March 7, 2007
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