?
Solved

Passing dynamically named checkbox values to an appended list (spectra/CF)

Posted on 2001-07-10
2
Medium Priority
?
277 Views
Last Modified: 2013-12-24
I don't know how difficult this question is to answer, but it's worth a lot to me: 200 points!

I created about fifty dynamically named checkboxes by looping through a set of objects and naming each checkbox with the objectID in the structure of each object. (I'm actually using Spectra objects here, but essentially I think this would be the same as straight CF)

When I submit the form, I want to take the ObjectIDs which come from the checked checkboxes and use listAppend() to create a comma-delimited list. I'll then insert the list into a property of an object I'm trying to update.

My code breaks down when I try to make the list. After I submit the form, I believe I have to loop through the same set of objects to recreate the names of the checkboxes and see if they were checked when submitted.

I thought that normally with checkboxes, if the box is checked when submitted then form.formfield for that checkbox would evaluate as "on" and if it is empty when submitted, it would evaluate as "off". But if I try to say <cfif form.Product[ct].objectID eq "on"> then append the ID to the list, it never works because form.product[ct].objectid always evaluates to "form.74DB80CD-593B-11D5-9C440090277322BD" or whatever the ID of the current object is.

Here is my most recent rendition of my code (note that I get the content from a Spectra content-object database):

<!--- Get all the product Overviews to populate checkbox form items and make "productList" list--->
      <cfa_contentObjectGetMultiple
            dataSource = "#prgn_corp_db#"
               typeID = "#tpsProductOverview#"
               r_stObjects = "stProducts"
                >

      
       <cfa_structSortCommonSubkeys
                struct = "#stProducts#"
                commonSubKey = "psSortOrder"
            sortType = "numeric"
                sortOrder = "asc"
                r_aSortedKeys = "productKey"
            >      

<cfif isdefined("form.ApplyChanges")>

<!--- Establish ObjectID to update from Hidden Form Field --->
      <cfset url.objectid ="#form.objectid#">

<!--- Create list of Product UUIDs from selected form checkbox items. --->

<cfset productList = "">
      
<cfloop list=#arraytolist(productKey)# index="ctX">
      <cfset productUUID = replace(stProducts[ctx].objectid, "-", "_", "all")>
<!--- This is the problem! --->
      <cfif isDefined(evaluate(de('form.' & productUUID)))>
      <cfset productList = listAppend(productList, stProducts[ctx].objectID)>
      </cfif>
<!--- This is seemingly the end of my problem - my list is empty --->
      
</cfloop>       

<!--- update the content object property --->

<cfa_contentObjectData
        dataSource = "#prgn_corp_db#"
      ISOLanguage="en"
      objectID = "#form.objectid#"
      >
     
      <cfa_contentObjectProperty
      name="psAssociatedProducts"
      value="#productList#"
      >

</cfa_contentObjectData>


            
<cfif>

<!--- Read the Staged Object to which you want to add the list of Product UUIDs --->
   <cfa_contentObjectGet
      datasource = "#prgn_corp_db#"
      objectid = "#url.objectid#"
      r_stObject = "stProfile"
      >

<cfform name="Partnersform" action="pstPRGNPartnersEditOne.cfm?myaction=#URLEncodedFormat(myAction)#&typeid=#URLEncodedFormat(url.typeid)#" method="post">
<input type="hidden"  name="query_string" value="#cgi.query_string#">
<input type="hidden"  name="objectid" value="#url.objectid#">      

<!--- display checkboxes of all possible products that stProfile can be associated with --->
<table border="0" cellpadding="3" cellspacing="4" width="99%">

      <cfloop list="#arraytolist(productKey)#" index="ct">
      <tr>

      <td>
            <!--- replace all ID hyphens with underscores --->
          <cfset productUUID = replace(stProducts[ct].objectID, "-", "_", "all")>
            <cfif structKeyExists(stProfile.psAssociatedProducts, "#mylanguage#") and stProfile.psAssociatedProducts[mylanguage] contains "#stProducts[ct].objectID#">
            <cfinput type="Checkbox" name="#productUUID#" checked>
            <cfelse>
            <cfinput type="Checkbox" name="#productUUID#">
            </cfif>
      <font size="-3">#stProducts[ct].psProductTitle#</font>
      </td>
      
      </tr>
</cfloop>

</table>
<hr>
<input type="submit" NAME="ApplyChanges" value="Stage">  
</cfform>


0
Comment
Question by:KateDeJong
[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 Comments
 
LVL 1

Accepted Solution

by:
Drewbytes earned 800 total points
ID: 6272513
The problem is with your checkboxes.

Each checkbox has to have the same name, but you set the value as the productuuid, you then get all the ticked checkboxes upon submit (all unchecked ones are not passed) as a comma delimited list of the uuid values you want.

This small example shows a working example.

<cfif isdefined("form.submited")>
     value = <cfoutput>#form.test#</cfoutput>
     <cfabort>
</cfif>

<form action="index.cfm" method="post">
     <input type="checkbox" name="test" value="123">
     <input type="checkbox" name="test" value="456">
     <input type="checkbox" name="test" value="789">
     <input type=submit name="submited" value="go">
</form>
0
 

Author Comment

by:KateDeJong
ID: 6273358
Thanks for your help! I knew radio buttons needed the same name, but I thought checkboxes were separate entities!

I spent a long time trying to come up with a "complex" CF solution, and now it's been fixed in a matter of minutes.

-Kate
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

777 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