Solved

Coldfusion form select box - persist values after submit

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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

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…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

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