Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Clear text box

New Here ,
Feb 06, 2016 Feb 06, 2016

When selecting a checkbox I want to export the data to a text box. I have this code.

Trigger: Mouse Up

Action: Run a JavaScript

var one = this.getField("Check Box2");

var two = this.getField("Text6");

{two.value=one.value}

When clicked it puts the export data from Check Box2 into Text6. However, if I want to change my selection, it will not allow the new export data to be exported into Text6 as it already has the data from the previous selection in it. Any help on the code to clear Text6 before a selection is made in Check Box2 would be much appreciated.

TOPICS
Acrobat SDK and JavaScript , Windows
414
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 06, 2016 Feb 06, 2016

Is that code in the Mouse Up event of the "Check Box2" check box, or some other one?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 06, 2016 Feb 06, 2016

I actually put the code in the custom calculation script of Text6, and it works. However, I have discovered another problem. If the Checkbox is off, I get the default value "Off" in Text6, Can I change this default value of "Off" to something else?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 06, 2016 Feb 06, 2016

It was in the Mouse Up Trigger of the checkbox.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 06, 2016 Feb 06, 2016

You cannot change the value that the check box is set to when it is unchecked. It is fixed at the string "Off". The Mouse Up script of the check box could be:

// Mouse Up script for check box

(function () {

    // Get a reference to the text field

    var f = getField("Text6");

    // Populate the text field with a value depending on the state of this check box

    if (event.target.value !== "Off") {

        f.value = event.target.value;  // Export value of check box

    } else {

        f.value = "Something else";  // replace with whatever you want to display when unchecked

    }

})();

You original script might appear to work as a custom calculation script, but it's not correct.

[Edited to correct typo]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 06, 2016 Feb 06, 2016

I copied and pasted your code in the checkbox, Mouse Up Trigger and I get this "SyntaxError: unterminated string literal 8:at line 9"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 06, 2016 Feb 06, 2016
LATEST

Change this line:

if (event.target.value !== "Off) {

To:

if (event.target.value !== "Off") {

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines