Skip to main content
Participant
October 11, 2016
Answered

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

  • October 11, 2016
  • 1 reply
  • 735 views

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"

This topic has been closed for replies.
Correct answer George_Johnson

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];

1 reply

George_JohnsonCorrect answer
Inspiring
October 11, 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];

Participant
October 14, 2016

Thanks I'll try this out.