Solved

Coldfusion form select box - persist values after submit

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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