Validate if Field Exists on Form

Is there a way to validate if a field exists on a form?

I know that sounds crazy since I should be creating fields that I use… but I am reading a list of columns out of a database and I need to check if the form I am on has a field of the same name before doing a certain thing, changing the color on the field background. It all works until I run into calling the javascript method on a field that doesn’t exist. When that happens it stops working from then on… even if it gets to fields that do exist.

So I need to first check if the field is there before I call the color method… that way it won’t break when new fields are added.

Field values can be called in an event using “curly brackets”.

{field_x} = ‘field_x receive this value’;
{field_y} = [var3];
{field_z} = {field_y};

But I am unable to dynamically check a field using local variable… eg:

$str = “MyField”;
if(isset({$str})){
echo $str." Exists!";
}

I was needing this to make sure I could change the background color of a field using javascript… here is the solution I have working. My Javascript method code was modified to include a check for the field being called, like this:

if (document.F1[field]) {
document.F1[field].style.backgroundColor = color;
}

Its working.