2 Replies Latest reply on May 24, 2006 3:15 PM by Dan Bracuk

    Testing Rows in an Array

      Hi Folks -

      I was wondering if someone can point me in the right direction on how to test if a certain row within an Array exists.

      Here's the scenario -

      I have a user input screen on the web site.

      That page is generated by javascript doing a loop 10 times.

      So all the field variables would be Name1, Name2, Name3, etc
      On this page a user could delete a person before submitting the result set, such as Name2.

      After the page is submitted, the number in the variables(Name1) are used to assign it into the array position.
      So Name1 goes into Array[1][1] = Name1, Name3 goes into Array[3][1] = Name3, etc.

      I am only giving a high level detail here... but suffice it to say that doing a loop over the form. values
      and assigning the Array position independent of the Form variable is not an option. There are other dependencies.

      So is there a way to test if Array[2][1] exists. I have tried a few things, but not success.

      Any and all ideas are appreciated.

        • 1. Re: Testing Rows in an Array
          BKBK Adobe Community Professional & MVP
          Springs to mind:

          xArray = ArrayNew(2);
          xArray[1][1] = "1";
          xArray[2][1] = "2";
          xArray[2][2] = "4";

          <!--- Your own custom version of "isDefined()" --->
          <cfcatch type="Expression">
          <cfset x="does not exist">

          xArray[1][1]: <cfoutput>#xArray[1][1]#</cfoutput><br>
          xArray[2][1]: <cfoutput>#xArray[2][1]#</cfoutput><br>
          xArray[2][2]: <cfoutput>#xArray[2][2]#</cfoutput><br>
          xArray[1][2]: <cfoutput>#x#</cfoutput>

          • 2. Re: Testing Rows in an Array
            Dan Bracuk Level 5
            It would be easier to do this without the array. You can access your form variables with syntax that resembles:

            <cfloop from = "1" to = "5" index = "ii">

            or maybe like this

            Assuming you are looking for a checked checkbox to delete the record,

            <cfif isDefined("form.deleteme[ii]")>
            bye bye