Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Problem

Status
Not open for further replies.

beejay58

Technical User
Sep 11, 2003
12
0
0
NZ
I am using CFDIRECTORY to display the contents of any selected directory in a form. Each filename is loaded to an array and has a checkbox next to it, so that it can be marked for deletion, the value of which is also assigned to an array.

I am then attempting to pass the 2 arrays to another template where I can perform a CFFILE delete for files corresponding to each 'checked' box.

I am so nearly there but cannot pass the arrays to another template. I have tried creating a function to build a list of filenames as each box. I am assuming I can pass a list to another template ? However, I cannot get this going either !

I am sure that this has been done by someone out there - any clues, I am pulling my hair out.

Beejay
 
Can you not use the return value of the checkboxes directly and use the list function to extract the filenames, loop over the list and delete the filenames in the list.
Am I missing the boat completely? Post some code if this doesn't make sense.

Erwin Oosterhoorn
Analyst Programmer,
ice hockey player/fan.
 
Erwin,

no you are bang on in your assumption as to what I am trying to do. I am not skilled in Javscript but put together a function which I called when each button was clicked - this I tested with an alert message to confirm it was being called. However, the ColdFusion variables from my form do not seem to be passed to the Javascript function.

Whenever I insert CF tags within the Javascript function to add to the list I attempting to create, nothing much seems to happen - the pop-up alet stops working too. Then, when I send the list to the next page by submitting the form (with the list embedded as a 'hidden' value) and output it, it is empty.

If you can suggest some code....

Many thanks for your comments

Beejay
 
If you're submitting the values in a form, http posts (ie - form submissions) don't really allow for passing arrays, unfortunately.

But I think what Erwin was elluding to was the fact that, if you have several checkboxes all named the same, the value that's passed to the form for that variable is a comma-separated concatenation of all the values that are checked.

In other words, if I have a form that looks like:
Code:
  File 1: <input type=&quot;checkbox&quot; name=&quot;selectedFiles&quot; value=&quot;filename1.txt&quot;><br />
  File 2: <input type=&quot;checkbox&quot; name=&quot;selectedFiles&quot; value=&quot;filename2.txt&quot;><br />
  File 3: <input type=&quot;checkbox&quot; name=&quot;selectedFiles&quot; value=&quot;filename3.txt&quot;><br />
  File 4: <input type=&quot;checkbox&quot; name=&quot;selectedFiles&quot; value=&quot;filename4.txt&quot;><br />
and I checked the second and third checkboxes and submitted the form, the action page would receive a value for
Code:
#FORM.selectedFiles#
that looked like:
Code:
    &quot;filename2.txt,filename3.txt&quot;

So you could easily loop over that list using ColdFusion's list functionality, and do whatever you want:
Code:
   <CFLOOP list=&quot;#FORM.selectedFiles#&quot; index=&quot;whichFile&quot;>
      <CFFILE action=&quot;delete&quot; file=&quot;#whichFile#&quot;>
   </CFLOOP>



-Carl
 
Carl, that's exactly what I had in mind. Just make sure that there are no comma's in your values, what shouldn't be if they are filenames.
Beejay, if you need a hand with some of the code let us know, remember that if you want to use javascript and Cold Fusion the CF code is run before the page is loaded. You can't mix javascript and CF functions at run time.


Erwin Oosterhoorn
Analyst Programmer,
ice hockey player/fan.
 
Guys,

many thanks for your assistance - all working fine now


Beejay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top