Skip to main content
December 14, 2016
Question

Map field-name to checkbox

  • December 14, 2016
  • 2 replies
  • 427 views

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 has been closed for replies.

2 replies

Inspiring
December 14, 2016

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.

try67
Community Expert
Community Expert
December 14, 2016

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

try67
Community Expert
Community Expert
December 14, 2016

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