Redisplay Multiple-Select box

Results 1 to 3 of 3

Thread: Redisplay Multiple-Select box

  1. #1
    Mark Caldwell Guest

    Default Redisplay Multiple-Select box

    I have a multiple-select select box that I want to redisplay after the form is submitted with the previously chosen options preselected. (i.e. user chooses options 4, 6, and 12 and after form is submitted, page is redisplayed with 4, 6 and 12 already selected.)<BR><BR>With a single-select box, I can just compare each value that I&#039;m putting in the box with the value of Request.Form("FieldName") and adding the SELECTED option. But with a multiple-select box, I have a comma-delimited string of numbers.<BR><BR>If I use InStr, then it thinks that value 2 should also be selected because the number 2 appears as part of value 12, and InStr says it is in there. BUT I only want the true values chosen.<BR><BR>Got any good ideas other than converting my string to an array and looping through the array for every comparison combination? Anyone know of a delimited version of InStr?<BR><BR>Thanks in advance!<BR><BR>Mark

  2. #2
    Join Date
    Dec 1969

    Default Actually...

    ...looping through an array after doing SPLIT isn&#039;t all that bad. I was surprised how well it performs compared to INSTR.<BR><BR>HOW-SOME-EVER...<BR><BR>How about this:<BR><BR>&#060;%<BR>prior = "#" & Replace( prior, ", ", "#" ) & "#"<BR>...<BR>Do Until RS.EOF<BR>&nbsp; &nbsp; sel = ""<BR>&nbsp; &nbsp; curID = RS("theID")<BR>&nbsp; &nbsp; If InStr( prior, "#" & curID & "#" ) &#062; 0 Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; sel = " SELECTED "<BR>&nbsp; &nbsp; End If<BR>&nbsp; &nbsp; Response.Write "&#060;OPTION Value=&#039;" & curID & "&#039;" & sel & "&#062;" & rs("Description") & vbNewLine<BR>&nbsp; &nbsp; RS.MoveNext<BR>Loop<BR>%&#062;<BR><BR>See the trick? If your list *was*<BR>&nbsp; &nbsp; &nbsp; &nbsp; 17, 33, 82<BR>then the replace changes it to<BR>&nbsp; &nbsp; &nbsp; &nbsp; 17#33#82<BR>and we tack on the front and end and get<BR>&nbsp; &nbsp; &nbsp; &nbsp; #17#33#82#<BR>and now when we search for #3# we don&#039;t get a false match on #33#, of course!<BR><BR>Obviously, you can use any character instead of the #, so long as it doesn&#039;t appear in the values. You could even use vbLF or Chr(8) or something like that, if you wanted to.<BR><BR><BR>

  3. #3
    Mark Caldwell Guest

    Default RE: Actually...

    Of Course! Thanks for jarring my brain.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts