Solved

Coldfusion form select box - persist values after submit

Posted on 2012-03-26
3
829 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
Comment Utility
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
Comment Utility
@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
Comment Utility
my question wasn't answered
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

15 Experts available now in Live!

Get 1:1 Help Now