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

Assigning a value to a text field from selecting a radio button

Community Beginner ,
Oct 10, 2016 Oct 10, 2016

I'm trying to assign a value to a text field when they choose a radio button.  It has worked before but now when I enter the Javascript in the Custom Calculation script of the text field, it disappears and remains blank.  I don't know how to resolve it.  This is the Javascript I tried to use

if(this.getField("Package").value == "Off") event.value = "";

if(this.getField("Package").value == "Package1") event.value = "400";

if(this.getField("Package").value == "Package2") event.value = "600";

if(this.getField("Package").value == "Package3") event.value = "700";

if(this.getField("Package").value == "Package4") event.value = "800";

if(this.getField("Package").value == "Package5") event.value = "500";

if(this.getField("Package").value == "Package6") event.value = "700";

if(this.getField("Package").value == "Package7") event.value = "800";

if(this.getField("Package").value == "Package8") event.value = "900"

TOPICS
Acrobat SDK and JavaScript , Windows
693
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

correct answers 1 Correct answer

LEGEND , Oct 10, 2016 Oct 10, 2016

Check the JavaScript console for errors by pressing Ctrl + J.

Also, it could be simplified to this:

// Set up an object to associate the possible field values with a corresponding number

var oVals = {

    "Off" : "",

    "Package1" : 400,

    "Package2" : 600,

    "Package3" : 700,

    "Package4" : 800,

    "Package5" : 500,

    "Package6" : 700,

    "Package7" : 800,

    "Package8" : 900

};

// Set this field's value

event.value = oVals[getField("Package").valueAsString];

Translate
LEGEND ,
Oct 10, 2016 Oct 10, 2016

Check the JavaScript console for errors by pressing Ctrl + J.

Also, it could be simplified to this:

// Set up an object to associate the possible field values with a corresponding number

var oVals = {

    "Off" : "",

    "Package1" : 400,

    "Package2" : 600,

    "Package3" : 700,

    "Package4" : 800,

    "Package5" : 500,

    "Package6" : 700,

    "Package7" : 800,

    "Package8" : 900

};

// Set this field's value

event.value = oVals[getField("Package").valueAsString];

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 Beginner ,
Oct 14, 2016 Oct 14, 2016
LATEST

Thanks I'll try this out. 

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