Others have sent in suggestions, but I'd like to show another way of
doing it as well... with UDFs! I have an article coming out for CFDJ
that discusses this concept, but the idea is simple. You can use a UDF
to quickly create structures and, if you know what you are doing, safely
append to the local scope. Watch:

Original:

 // DEPARTMENT 1
 item.department = 'Department 1;
 item.name = 'Bill Jones;
 item.email = '[EMAIL PROTECTED];
 
 additem = arrayAppend(request.contact, item);
 
 // DEPARTMENT 2
 item.department = 'Department 2;
 item.name = 'Joe Jones;
 item.email = '[EMAIL PROTECTED];

With UDFs:

request.contact = arrayNew();
addContact("Department 1","Bill Jones","[EMAIL PROTECTED]");
addContact("Department 2","Jpe Jones","[EMAIL PROTECTED]");
etc...


function addContact(dpt,name,email) {
        var d = structNew();
        d.dpt = dpt;
        d.name = name;
        d.email = email;
        arrayAppend(request.contact,d);
} 


=======================================================================
Raymond Camden, Principal Spectra Compliance Engineer for Macromedia

Email    : [EMAIL PROTECTED]
Yahoo IM : morpheus

"My ally is the Force, and a powerful ally it is." - Yoda 

> -----Original Message-----
> From: Owens, Howard [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, January 10, 2002 7:41 PM
> To: CF-Talk
> Subject: array - structure question
> 
> 
> On my Application.cfm page, I want to use an array to 
> populate a feedback
> form with contacts, and the response page with the 
> corresponding e-mail
> addresses in the "to" attribute.
> 
> This seemed more practical than storing the info in a database, for an
> amount of data this limited, but still give some flexibility 
> for making
> changes down the road.
> 
> So here's a snip from within my CFScript:
> 
> 
> // department mail addresses
> // e-mail addresses and contact information dropped into an 
> array of structs
> to facilitate retrieval and updating
> 
> request.contact = arrayNew(1);
> item = structNew();
> 
> 
> // DEPARTMENT 1
> item.department = 'Department 1;
> item.name = 'Bill Jones;
> item.email = '[EMAIL PROTECTED];
> 
> additem = arrayAppend(request.contact, item);
> 
> // DEPARTMENT 2
> item.department = 'Department 2;
> item.name = 'Joe Jones;
> item.email = '[EMAIL PROTECTED];
> 
> additem = arrayAppend(request.contact, item);
> 
>  .... and so on.
> 
> The problem is, the last entry keeps overwriting the 
> structures at each
> array position.  In other words, request.contact[1] contains 
> the data for
> array position 10, and position 2 contains the data for 10 
> ... and so on.
> 
> Should position 1 of the array remember what it had initially 
> and not get
> over written by the time the 2 position is created, and so on?
> 
> How can I get each position in the array to have structures 
> with discrete
> and unique information?
> 
> H.
> 
> 
> Howard Owens
> Internet Operations Coordinator
> www.insidevc.com
> [EMAIL PROTECTED]
> AIM: GoCatGo1956
> 
> 
______________________________________________________________________
Get Your Own Dedicated Windows 2000 Server
  PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusionb
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to