Testing valueOf() for a null value

Hi all

With reference to my previous post regarding referencing form/field names with variables.

I am trying to execute a command if a null value is present within a field
The following will output the field value if a value is present in the field, using variables for form name and field from my arrays.

var field_value = forms[form_name][form_field].valueOf()
application.output(field_value)

If a null value is present i get an error

Cannot call method “valueOf” of null

I have tried the following to no avail, if someone could advise it would be much appreciated

if (!forms[form_name][form_field].valueOf())
{
application.output(‘null’)
}

else
{
application.output(‘success’)
}

Regards

McCourt Cordingley

Hi McCourt,

You don’t really have to use the valueOf() function to get the value. You can simply reference it like so:

if ( forms[form_name][form_field] == null ) {
     application.output('null');
} else {
     application.output('success')
}

Hope this helps.

Hi

This is just what I needed,

Regards

McCourt Cordingley