Skip to main content
Dec 14, 2016 10:59 PM UTC
Question

Map field-name to checkbox

I am attempting to automatically check a checkbox when a hidden field has a  certain description.

Very new to JavaScript.

My validation script is:

if (+event.value=="Text") this.getField("Text1 Checkbox").checkThisBox(0, True);

Would someone please explain why this doesn't work and what the correct script should be.

Any help is greatly appreciated.

This topic is closed to new replies. Start a new post to keep the conversation going.

5 replies

Inspiring
Dec 14, 2016 11:51 PM UTC

The + sign is used to easily convert a field value to a number explicitly, which is usually only done when the value will be used later in the script as a number, as when summing the values from several fields. (Blank fields values are returned as empty stings.) In this case, you're using the value as a string, so you should not only remove the +, but you should use the valueAsString property instead of the value property, something like:

if (event.valueAsString == "Text") this.getField("Text1 Checkbox").checkThisBox(0, True);

This will ensure that it always works. Note that the following would not:

if (event.value == "012345") this.getField("Text1 Checkbox").checkThisBox(0, True);

if the user entered "012345" since the leading zero would not be included when the result is automatically cast as a number and then compared to a string. It would work when using the valueAsString property.

Translate
try67
Community Expert
Community Expert
Dec 14, 2016 11:53 PM UTC

Also, replace "True" with "true" (without the quotes).

Translate
try67
Community Expert
Community Expert
Dec 14, 2016 11:03 PM UTC

Why did you add a plus-symbol before event.value? Do you know what that means?

Translate