• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Testing Rows in an Array

Explorer ,
May 24, 2006 May 24, 2006

Copy link to clipboard

Copied

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.

Thanks.
TOPICS
Advanced techniques

Views

240

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2006 May 24, 2006

Copy link to clipboard

Copied

Springs to mind:

<cftry>
<cfscript>
xArray = ArrayNew(2);
xArray[1][1] = "1";
xArray[2][1] = "2";
xArray[2][2] = "4";
</cfscript>

<!--- Your own custom version of "isDefined()" --->
<cfscript>
x=xArray[1][2];
</cfscript>
<cfcatch type="Expression">
<cfset x="does not exist">
</cfcatch>
</cftry>

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2006 May 24, 2006

Copy link to clipboard

Copied

LATEST
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">
<cfoutput>
form.name[#ii#]

or maybe like this
#form.name[ii]#

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

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation