Amir
Amir

Reputation: 4770

How do I grab the variable NAME and not the VALUE of the variable in ColdFusion?

The basic idea is this: I have a form that generates form fields dynamically so let's say there are 5 evens people can sign up for (they all cost $10) then those 5 evens will be displayed. Like this:

          <tr>
            <th><label>#SeminarWisTitle#</label></th>
            <td>
            <label><input type="checkbox" name="#SeminarWisID#" value="10.00" onclick="CheckChoice(this);" onfocus="startCalc();" onblur="stopCalc();" class="checkbox" /> Individual Webinar ($119)</label>
            </tr>
          </cfoutput>

Now because of the Javascript the value on all these events will be 10.00 but the NAME of the form field will be unique, and that is what I actaully want to store in the database.

This is the code I've written:

<cfparam name="seminarBulkSignUp_List" default="">
            <cfoutput query="qSeminarWisTwo">
                <cfparam name="FORM.#SeminarWisID#" default="">

                <cfif #FORM[#SeminarWisID#]# neq "">
                    <cfset seminarBulkSignUp_List = ListAppend(seminarBulkSignUp_List, #FORM[#SeminarWisID#]#)>
                </cfif>
            </cfoutput>

            <cfset FORM.SeminarWisTitle = #seminarBulkSignUp_List#>

So with this code, I run a query for ALL the possible events, and then just check against the form that has been submitted to see which ones are "blank" as in not selected, and the ones that are selected i want to add to a list to store in the database.

Now this works as far as letting me know which events were selected and which not, but i want the list to compile the actual FORM FIELD names not the value they have. How would I do that?

Upvotes: 1

Views: 140

Answers (1)

Shawn Holmes
Shawn Holmes

Reputation: 3762

<cfoutput>
  <cfloop list="#StructKeyList(FORM)#" index="thisField">
    My field name: #thisField#<br/>
    My field value: #FORM[thisField]#<br/>
  </cfloop>
</cfoutput>

Apply as necessary.

Upvotes: 7

Related Questions