Solved

Coldfusion form select box - persist values after submit

Posted on 2012-03-26
3
833 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mixing cold fusion headers and footers with PHP body 6 56
multi page pdf 4 82
Coldfusion Table display that allows inline edit 3 37
Coldfusion retrieve dynamic values 1 30
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now