Is there any way to determine whether a variable has properties?

R

Ramon F Herrera

Hello,

I have a table whose entries are not all defined. My current code
looks like this:

var shouldHide = noEarnings.isBoxChecked(0);

for (var i = 0; i < rows; i++)
for (var j = 0; j < 2; j++)
if ((i!=3 || j!=1) && (i!=4 || j !=1) && (i!=6 || j!=1)) //
<-- These are the undefined entries
amountTable[j].hidden = shouldHide;
else
console.println("Table " + (i+1) + ", " + (j+1) + " is
undefined");

Naturally, I would like to write more general code, checking whether
the entry exists before trying to [un]hide it.

TIA,

-Ramon

ps: This is JavaScript for Acrobat forms.
 
T

Thomas 'PointedEars' Lahn

Ramon said:
var shouldHide = noEarnings.isBoxChecked(0);

for (var i = 0; i < rows; i++)
for (var j = 0; j < 2; j++)
if ((i!=3 || j!=1) && (i!=4 || j !=1) && (i!=6 || j!=1)) //
<-- These are the undefined entries
amountTable[j].hidden = shouldHide;
else
console.println("Table " + (i+1) + ", " + (j+1) + " is
undefined");

Naturally, I would like to write more general code, checking whether
the entry exists before trying to [un]hide it.


In the most simple but compact form:

for (...)
{
for (...)
{
var row = amountTable, cell;
if (row && (cell = row[j]))
{
cell.hidden = shouldHide;
}
}
}

RTFM, RTFFAQ, STFW.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top