Solved

Coldfusion form select box - persist values after submit

Posted on 2012-03-26
3
843 Views
Last Modified: 2012-03-27
Hi,

I have a coldfusion form where I have a select box and a multi select box. They are being populated from a query. When the user first submits the form, based on some server side validation, the database is either updated with the values in the select boxes. If validation on server side fails, then I need to display the values that the user had selected, instead of the values being populated from the query. How do I make the values of the select box persist?

Here is what I have now but it doesn't work:

<select name="sel_Athletes_#currentrow#" id="sel_Athletes_#currentrow#">
    <option value="1">-------------</option>
    <cfloop query="QAthletes">
        <cfif QAthletes.athlete neq "">
            <cfif form.submittedWithDupes is "false">
                <option value="#QAthletes.athlete#" <cfif form["sel_Athletes_" & currentrow] eq QSchools.athlete>selected="selected" </cfif>>#QAthletes.athlete#
                </option>
            <cfelse>
                <option value="#QAthletes.athlete#" <cfif QAthletes.athlete eq QSchools.athlete>selected="selected" </cfif>>#QAthletes.athlete#
                </option>
            </cfif>
        </cfif>
    </cfloop>
</select>
0
Comment
Question by:roger_v
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
digicidal earned 500 total points
ID: 37769736
You have a problem with using the value of 'currentrow' as it's not properly named.  You have two queries that you are looping over.  The select name comes from the QSchools.currentrow value but the conditional for selection comes inside the QAthletes query loop.  You need to explicitly name the variable or it will assume you mean the current row of QAthletes not QSchools.

I see a couple other issues or at least I have questions - but that's the first thing to fix.

The most important issue is to make sure you are telling ColdFusion which structure (query) it needs to look for the value of the 'currentrow' key.  Currently it is checking the values of the subsequent 'N' selects rather than the values of the current one.  To explain better it is looking for the value of the select numbered the same as the current row of the athletes query position.  

This shouldn't work (at least in my mind - but I'm tired) unless you have only one row in each query... otherwise if there are 2 schools and 6 athletes the last 4 values can't even be evaluated because there aren't selects numbered 3-6 which should cause a critical error.  Even if there are the appropriate number of controls (i.e. you have more schools in the recordset than athletes) you will still not be looking at the correct control for the conditional to work.

I'm also assuming that the ID is 'athlete' for both QSchools and QAthletes (so there's a One-to-One relationship).  Otherwise is it not possible for a school to have more than one athlete?  Maybe not and this is for a tournament roster or something where each school can only have one representative?  I'm just asking these questions because there might be a better way of presenting the options to the user.
0
 
LVL 1

Author Comment

by:roger_v
ID: 37772051
@digicidal:

Fixed the currentrow by specifying the queryname, but the problem remains. Looks like I'll have to use ajax for this.
0
 
LVL 1

Author Closing Comment

by:roger_v
ID: 37772057
my question wasn't answered
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question