Solved

Use of Arrays with <CF_TwoSelectsRelated>

Posted on 2004-04-30
4
351 Views
Last Modified: 2013-12-24
I am using the custom tag <CF_TwoSelectsRelated> and it seems to work fine if the parameters, Name1 and Name2, are simple variables.  However, if I try to use array elements (see below), I get an IE Script Error.  That is, the following code works fine:

<CF_TwoSelectsRelated
                    query="qryGetContacts"
      Name1="AssignedToOrg1"
      Name2="ContactID1"

The following code gets the script error and results in no choices in the second select:

<CF_TwoSelectsRelated
      query="qryGetContacts"
      Name1="AssignedToOrg[1]"
      Name2="ContactID[1]"

Can I use (or modify) the custom tag to accomodate the use of array elements?
0
Comment
Question by:Rich0507
  • 2
4 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 10962549
You cannot use an array here because the Name1 and Name2 are query columns.  So I am not sure what you are trying to do.

If you want to write the tag on your own you can.  It would be like this (example for selecting a person - Buyer -  based on a department) :

<script type="text/javascript" language="JavaScript">
<!--
/* Dynamically populate Buyer select box based on seleted DepartmentID */
// Create an array to hold Buyers
var BuyerArray = new Array;

// Define a custom Javascript object type to represent a single Buyer
function Buyer(BuyerUsername, DepartmentID, BuyerName)
{
      this.BuyerUsername = BuyerUsername;
      this.DepartmentID = DepartmentID;
      this.BuyerName = BuyerName;
}
<!--- For each Buyer, append a new Buyer object to the array of Buyers --->
<cfoutput query="GetBuyers">
      BuyerArray[BuyerArray.length] = new Buyer("#JSStringFormat(Username)#", "#JSStringFormat(DepartmentID)#", "#JSStringFormat(BuyerName)#");
</cfoutput>

/* Fill the Buyer select box based on the DepartmentID */
function fillBuyers()
{
      // Stop if there is no selected ParentID
      if (document.AddIssue.DepartmentID.selectedIndex == -1)
      {
            return;
      }
      
      var DepartmentID = document.AddIssue.DepartmentID.options[document.AddIssue.DepartmentID.selectedIndex].value;
      
      // Remove all options in the Buyer select box
      document.AddIssue.Buyer.options.length = 0;
      
      // For each item in the Buyer array ...
      for (var i = 0; i < BuyerArray.length; i++)
      {
            // If the Buyer's DepartmentID is the same as the currently selected DepartmentID
            if (BuyerArray[i].DepartmentID == DepartmentID)
            {
                  // Put a new option in the Buyer select box
                  document.AddIssue.Buyer.options[document.AddIssue.Buyer.options.length] = new Option(BuyerArray[i].BuyerName, BuyerArray[i].BuyerUsername);
            }
      }
}
-->
</script>


<select name="DepartmentID" onChange="fillBuyers()" style="width: 200px;">
      <option value=""></option>
      <option value="GM">General Merchandise</option>
      <option value="TR">Trade</option>
      <option value="TX">Text</option>
</select>

<select name="Buyer" style="width: 200px;"></select>
0
 

Author Comment

by:Rich0507
ID: 10963216
According to the documentation for the custom tag, <CF_TwoSelectsRelated>:  "NAME1 and NAME2 are the names of the two SELECT list elements to be included on the form. The SELECT element with NAME1 will appear first on the page, and the one with NAME2 will be second. For instance, if you use NAME2="Selection", then whatever the user chooses in the second SELECT will be available to for your use as #Form.Selection# in the next template."  [NOTE: there is no mention that these elements are or must be query column names.]

I am creating a form with multiple lines, and would like to capture these multiple lines of data in an array.  So I want to create a loop where I repeatedly invoke the <CF_TwoSelectsRelated> tag.  And I want to capture the users choices (from multiple boxes) in an array (Selection[1], Selection[2] rather than in multiple single variables (Selection1, Selection2).  I am not proficient in javascript, so I didn't understand the solution that was recommended.
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 250 total points
ID: 10963252
Oh whoops you are right I meant select box names not query column names.  Sorry.

It is still the same principle - you need to use a simple name for the select.  It cannot be named an array cell.

You cannot caputre the results inro an array.

If yyou name them the same they will be submitted as a comma delimited list.

Or the alternative is to name them sequesntially then in cold fusion when youprocess the form you can put them intoa an array in COLD FUSION - not javascript and then continue to process as an array.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now