• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

Retaining values in multi select box

I've got a form posting back to itself. User selects one or more values from a multiselect box.  If only one value is selected, on postback the value remains selected.  If more than one value is selected, no values remain selected.

Is there a way to have the multiple selections showing on post back?

Thanks,

JK
0
joekus
Asked:
joekus
  • 3
  • 2
  • 2
1 Solution
 
danrosenthalCommented:
Are you doing something like this?

<SELECT name="test" multiple>
  <CFQUERY name="myquery">
    <OPTION value="#value#" <CFIF LISTFIND(form.test,value)>SELECTED</CFIF>>#display#
  </CFQUERY>
</SELECT>
0
 
joekusAuthor Commented:
Sorry.  New to ColdFusion and have inherited some of this code...

<cfSELECT NAME="vArea" id="Area" size="3" tabindex="0" multiple = "yes" onchange="javascript:focus(this.selectedIndex);">
    <cfloop from="1" to="9" index="i">
        <cfset anum=#NumberFormat(i,"09")#><cfset aid="a" & #anum#>
        <cfoutput>
            <option  value="#anum#"<cfif IsDefined("form.vArea")  and isdefined("form.Selection") and form.vArea Is #anum# and listfind(form.Selection,qSelect.Area)>selected</cfif>>Area #i#</option>
       </cfoutput>
    </cfloop>
</cfSELECT>
0
 
danrosenthalCommented:
Not sure exactly what the code is SUPPOSED to do, as I have now idea what form.selection and qselect.Area are for. But here is my best guess:

<CFPARAM name="form.vArea" default="#qSelect.Area#">
<cfSELECT NAME="vArea" id="Area" size="3" tabindex="0" multiple = "yes" onchange="javascript:focus(this.selectedIndex);">
    <cfloop from="1" to="9" index="i">
        <cfset anum=NumberFormat(i,"09")>
            <cfset aid="a" & anum>
        <cfoutput>
            <option  value="#anum#"<cfif listfind(form.vArea,anum)>selected</cfif>>Area #i#</option>
       </cfoutput>
    </cfloop>
</cfSELECT>



0
Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

 
bwasyliukCommented:
Not sure where this is evaluating from : listfind(form.Selection,qSelect.Area)

But Dan was pointing you in the right direction.  As I see it, submitting this form will multiple form.vArea values selected will have a #form.vArea# value like "a01,a04,a05" or whatever is selected.

Thus, the code :::::::::  form.vArea Is #anum#
will need to be more like Dan's example::::::::  LISTFIND(form.vArea,anum) > 0

The other condition, however - may still cause you some issues, because it is not obvious what "listfind(form.Selection,qSelect.Area)" will evaluate to.

Ben
www.scheduleforce.net
0
 
bwasyliukCommented:
Sorry Dan - was typing while you posted your other comment...
0
 
danrosenthalCommented:
No problem, looks like we are in agreement anyway :)
0
 
joekusAuthor Commented:
Thanks, Dan.  Even with my unclear information you were able to de-cipher it.  Your guess was right on.

Thanks, Ben for clarifying comment.

JK
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now