• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

Creating a CF Edit form with data from SQL database

I am completely losing it here and I have done this before but for the life of me cannot figure out how I did it.

I have a user account form that I want people to edit.  The form opens, and I want the data to display that of a specific user account.  So I have a grid, the user clicks on a user, it opens up with an AJAX call as a popup type box greying out the rest of the page.  I have select boxes, how do I display what is currently in the database for that user first and then display all the other values in the select box.

       <SELECT id="edtRole" NAME="edtRole" STYLE="width:154px;">
                         <cfoutput>
                <cfloop query="qryRoles">
                    <option value="#app_role_id#">#app_role_dscr#</option>
                </cfloop>
                </cfoutput>
       </SELECT>
0
Lee R Liddick Jr
Asked:
Lee R Liddick Jr
  • 2
1 Solution
 
_agx_Commented:
(I'm heading to sleep, but ... ) Normally you just use the current db value to preselect the list option, rather than having it appear 1st , ie:

..
      <cfloop query="qryRoles">
            <option value="#app_role_id#"  <cfif qryRoles.app_role_id eq currentDBValues.app_role_id>#app_role_dscr#</option>
      </cfloop>
...

Open in new window


But if you prefer, you can also run a separate db query for the current value and description. Then output it as the 1st option.

       <SELECT id="edtRole" NAME="edtRole" STYLE="width:154px;">
       <cfoutput>
               <option value="#currentDBValues.app_role_id#">#currentDBValues.app_role_dscr#</option>
                <cfloop query="qryRoles">
                    <option value="#app_role_id#">#app_role_dscr#</option>
                </cfloop>
                </cfoutput>
       </SELECT> 

Open in new window

0
 
_agx_Commented:
> <option value="#app_role_id#"  <cfif qryRoles.app_role_id eq currentDBValues.app_role_id>#app_role_dscr#</option>
     

Ugh... obviously my fingers went to sleep early. The 1st option should be:

<cfloop query="qryRoles">
      <option value="#app_role_id#"  
          <cfif qryRoles.app_role_id eq currentDBValues.app_role_id>selected</cfif>>
            #app_role_dscr#
   </option>
</cfloop>
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now