473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to validate an array element?

219 100+
I'm trying to validate whether or not an array element has been created.

Here is what one of the arrays could look like:

commentid[1] = undefined
commentid[2] = undefined
commentid[3] = 1
commentid[4] = 1
commentid[5] = undefined
commentid[6] = 1

I want to check if a certain array element is set to 1, but I'm getting errors in the code below because commentID[1] is undefined. How can I have the code not evaluate if it's undefined. I've tried using isDefined() and isValid() as well.

Expand|Select|Wrap|Line Numbers
  1. <cfoutput query="getComments">
  2.            <cfif #commentList[commentID]# eq 1>
  3.                 Valid!!!!
  4.         <cfelse>
  5.                not valid!!!
  6.     </cfif>
  7. </cfoutput>
  8.  
Mar 12 '08 #1
5 3770
acoder
16,027 Expert Mod 8TB
isDefined() doesn't work with array elements. Set a variable to the array element and then test that instead.
Mar 12 '08 #2
dmorand
219 100+
I'm not able to set a variable to the array element if it's undefined. I tried it and I'm still getting CF errors. I think I'm just not thinking of the best way to handle this, but I'm stumped.

This is what I'm trying to accomplish:
I have a form with a section with a bunch of checkbox fields.
I'm retrieving the fields which were selected using a query. I know which numbers were checked, but now I want to have those fields checked off when the user goes into the form to edit their records.

I just need to either see if the query returned that specific value or not, and either check or not check the box.
Mar 20 '08 #3
acoder
16,027 Expert Mod 8TB
Then why not just use a list and loop over it checking the checkboxes which have a number in the list? Create the list (a string of numbers delimited by commas) using the query. To determine whether to check a checkbox or not, you could use listfind.
Mar 20 '08 #4
dmorand
219 100+
Then why not just use a list and loop over it checking the checkboxes which have a number in the list? Create the list (a string of numbers delimited by commas) using the query. To determine whether to check a checkbox or not, you could use listfind.
I'll give that a shot. It's so easy in my head, I just cant get the sql/cf code down right.

I'm too used to coding in proprietary systems....I need to get better acquainted with sql/cf.
Mar 20 '08 #5
acoder
16,027 Expert Mod 8TB
If you get stuck, post your attempted code, and I can suggest changes.
Mar 20 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Aaron P Frenger | last post by:
Hello All, I have a very large XML file that I would like to split up into a few smaller files, but still use only one schema. I am using Xerces C++ libraries. My idea is to have one schema...
6
by: Abby Lee | last post by:
I must confirm the user enters a value for each fund they need. I do not know how many fund entries there will be...it's expandable to handle each users needs. I must varify each fund they enter is...
9
by: Rob Mayo | last post by:
I have a bunch of XSD files in my assembly as embedded content that are read out via reflection and streams. My app creates the XML on the fly, and I want to validate it using the schema files...
3
by: Mike P | last post by:
I have an xml doucument that I want to validate with a XSD schema. I'm new to this and I don't know exactly how I make the references at the top of the documents so that the XSD file will validate...
1
by: aevans1108 | last post by:
Greetings All If this is the wrong place to post this question, please give me a push in the right direction. Thanks. I know there has to be a simpler way to do this, but this is as simple a...
1
by: Paul Cheevers | last post by:
Hi, I've been trying to write some schema to validate the Value element of an Eq element but to no avail. If the Value Element is off type DateTime then the node should be able to contain text...
0
by: SHC | last post by:
Hi all, I have a VC++ .NET 2003 - Windows XP Pro PC. I created a Win32 console application in my VC++ .NET 2003 and copied validateDOM.cpp, books.xml and books.xsd (see the attached files below)...
3
by: Rushi | last post by:
Hi All, Is it possible to Validate XML against XSD using two different XML files. scenario: There are two different XML file, one file contain element and count information and other one...
6
by: Jonny | last post by:
Hi, I'm trying to validate my xml against a xsd but I can't get it to work. Originally, I wanted to validate an xml string but since I didn't get that to work I tried to validate an xml file...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.