Skip to main content
Known Participant
November 11, 2016
Answered

Javascript Question - interactive PDF form - check box, text field.

  • November 11, 2016
  • 3 replies
  • 2754 views

HI Forum experts ,

I have created an interactive PDF form with check-boxes and text fields.  I wanted to know if it is possible for 'checkbox 1' to tick, when 'text field 1' has had text entered (JavaScript on the textbox?).  The check-boxes will be on another page and will track the progress of text box completion over time.

(The form is going to be used for an ongoing audit). 

If you know of a JavaScript / or how to do this - that would be greatly appreciated. Many thanks - Kind regards Kevin

This topic has been closed for replies.
Correct answer try67

Sure, it's possible. Enter this code as the custom validation script of the text field:

this.getField("checkbox 1").checkThisBox(0, (event.value!=""));

You can set the check-box as read-only to prevent the user from changing its value manually.

3 replies

sparrowk1Author
Known Participant
November 16, 2016

Hi Again, I would be grateful - if you can also help me with this (variation to above):

Is it possible to have 4 text fields, which activate a check box if at least one of them have text entered?

The JS for that would be fantastic. (I'll put it in correct place)

Again - really appreciated - thanks Kevin

try67
Brainiac
November 16, 2016

Use this code:

var v1 = this.getField("Text1").valueAsString!="";

var v2 = this.getField("Text2").valueAsString!="";

var v3 = this.getField("Text3").valueAsString!="";

var v4 = this.getField("Text4").valueAsString!="";

this.getField("checkbox 1").checkThisBox(0, (v1 || v2 || v3 || v4));

sparrowk1Author
Known Participant
November 16, 2016

Perfect! Many thanks.

I see some of the patterns in the JS - so this is definitely inspiring me to learn to a basic level.  I may have one last question ... if OK I'll post on this thread.

Thanks again

Kind regards Kevin

sparrowk1Author
Known Participant
November 15, 2016

Hi Try67,

Sorry to be a pain a variation on the above: Do you know if it is possible to have three text fields, and a check box, and the check box only ticks when all three text fields have had text entered? if so the JS for that would be fantastic. Appreciated - Kind regards Kevin

try67
Brainiac
November 15, 2016

The easiest way is to create another (hidden) text field and then enter this code as its custom calculation script:

var v1 = this.getField("Text1").valueAsString!="";

var v2 = this.getField("Text2").valueAsString!="";

var v3 = this.getField("Text3").valueAsString!="";

this.getField("checkbox 1").checkThisBox(0, (v1 && v2 && v3));

sparrowk1Author
Known Participant
November 15, 2016

Many thanks for the quick reply: I haven't been able to get this to work, the check box only ticks when I enter text for the three text boxes and the hidden text box.  Thanks Try67 - Anymore help greatly appreciated. Many Thanks Kevin

try67
try67Correct answer
Brainiac
November 11, 2016

Sure, it's possible. Enter this code as the custom validation script of the text field:

this.getField("checkbox 1").checkThisBox(0, (event.value!=""));

You can set the check-box as read-only to prevent the user from changing its value manually.

sparrowk1Author
Known Participant
November 14, 2016

Brilliant! really helpful - many thanks.