Question : How to get form variables in checkboxes, radio buttons, and select dropdown menus to pass back to a form, when I edit a userID.

ColdFusion 8
MS SQL Server 2005

Thanks to assistance from _agx_ and gdemaria I have been able to pass variables back to an edit form page, an example of which is here:

http://www.nbptsprincipals.org/admin/nbpts_registration.cfm?UserID=153

When I edit UserID=153, I am able to see most (not all) of the variables entered into the database table.

(This is a test UserID, and no harm can come in editing it.)

Here's my problem. Form variables in checkboxes, radio buttons, and select dropdown menus do not pass back to the form, when I edit a userID.

_agx_ suggested a useful way to pass back variables into a select menu, an example of which I give in the code box, below. That's a really useful method, but, this form has many select (or, cfselect) menus. I could apply _agx_'s method to every select menu, but that would introduce a lot of new code into this already very long application (approaching 1,200 lines).

Is there another way to pass back variables to select menus, checkboxes, and radio buttons? Do I have to modify every select menu, checkbox, and radio button in the form? This form is the largest and most complex application I have built so far. I would like to keep it as simple as I can.

I attach, below, two items:

1. _agx_'s method to pass back a variable to a select menu; and

2. examples of select menus, checkboxes, and radio buttons from my edit form

I am very grateful for any suggestions.

Eric
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
1. _agx_'s method to pass back a variable to a select menu

<!--- query to get existing topics for the current documentID --->

       <cfquery datasource="#ds#" name="GetSelectedTopics">
              SELECT DocumentTopicID
              FROM    tbl_Document_Has_Topic
              WHERE  DocumentID = <cfqueryparam cfsqltype="cf_sql_integer" value="#val(form.documentID)#">
       </cfquery>
     
       <!--- convert the DocumentTopicID values to a list --->
      <cfset form.SelectDocumentTopics = ValueList(GetSelectedTopics.DocumentTopicID)>

<cfselect name="SelectDocumentTopics"
size="8"
multiple="yes"
query="GetDocumentTopics"
queryPosition="below"
value="DocumentTopicID"
display="DocumentTopic"
selected="#form.SelectDocumentTopics#">
     <option value="0">Choose topic:</option>
</cfselect>



2. examples of select menus, checkboxes, and radio buttons from my edit form at nbpts_registration.cfm

select menu:

  <!--- script to make UserRoleID a required field  --->
<script type="text/javascript">
      function checkUserRole(theForm, theList, theValue) {
            return (theValue == "" ? false : true);
      }
</script>
    
     User Role:       
      <cfselect id="UserRoleID" name="UserRoleID" size="1"
    message="Enter User Role: Admin, Liaison, or Principal."
    required="Yes"
    onValidate="checkUserRole"
    validateAt="onSubmit,onServer">
                <option value=""> Choose User Role </option>
                <option value = "5">Principal</option>
                <option value = "3">Liaison</option>
                <option value = "1">Administrative</option>
</cfselect>




Checkbox:
<p><input type="checkbox" name="DegreeBachelors"> Bachelors</p>


Radio button:
<p>3. Do you know how to create a PDF from Microsoft files?  <span class="big rede31b23">*</span></p>
<p><input type="radio" name="CreatePDF" value="1"> Yes</p>
<p><input type="radio" name="CreatePDF" value="0"> No</p>

Answer : How to get form variables in checkboxes, radio buttons, and select dropdown menus to pass back to a form, when I edit a userID.

For radiobuttons/checkboxes, you could use a shortcut

<cfinput type="checkbox" name="ColumnName"
      value="1" checked="#myQuery.ColumnName eq 1#">

... OR use the old fashioned way

<cfinput type="checkbox" name="ColumnName"
      value="1" <cfif myQuery.ColumnName eq 1>checked</cfif>>

... where "1" is variable (the value of the current checkbox/radiobutton)
Random Solutions  
 
programming4us programming4us