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

script help - setting initial values

New Here ,
Jun 01, 2019 Jun 01, 2019

The first line doesn't seem to work to create a "null" value for the "event.value".

Right now the form's initial value is "negative" and I really need it to neither positive or negative. Preferably blank.

All three radio buttons are set to start as blank. Neither yes or no (1 or 0) is checked as a default value. The Pdf form must be considering that as a 0 anyway as the form displays a "Negative" as an initial result on the form.

thanks for your help.

Bob

event.value = "null";

var v1 = Number(this.getField("Radio Button 1").value);

var v2 = Number(this.getField("Radio Button 2").value);

var v3 = Number(this.getField("Radio Button 3").value);

if (v1+v2+v3>0) {

event.value = "Positive";

}

else event.value = "Negative";

TOPICS
PDF forms
1.1K
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 02, 2019 Jun 02, 2019

Yes, only it's "Off", not "off". Try this:

var v1 = this.getField("Radio Button 1").valueAsString;

var v2 = this.getField("Radio Button 2").valueAsString;

var v3 = this.getField("Radio Button 3").valueAsString;

if (v1=="Off" || v2=="Off" || v3=="Off") event.value = "";

else {

    var total = Number(v1) + Number(v2) + Number(v3);

    if (total>0) {

        event.value = "Positive";

    } else event.value = "Negative";

}

View solution in original post

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
Advocate ,
Jun 02, 2019 Jun 02, 2019

The value of an unchecked set of radiobuttons is "Off".

So, you would have to treat that condition first; either by suppressing the calculation and maybe give an alert about unsufficient data, or by replacing it with another value.

Number("Off") results to NaN (Not a Number), if I remember correctly. So, the sum of NaN plus other numbers is never > 0, and therefore, your result is always "Negative".

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 ,
Jun 02, 2019 Jun 02, 2019

I should have said the script works in that at any point someone chooses a "Yes", the result flips to Positive and selecting all "No" values results in Negative.

So, are you saying if I create an if/else that says if v1 or v2 or v3 = "off" ( should I then change my button values to yes and no but then you can't add strings...)

event.value = ""

else

run the rest of the script

Am I in the ballpark?

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 ,
Jun 02, 2019 Jun 02, 2019

Yes, only it's "Off", not "off". Try this:

var v1 = this.getField("Radio Button 1").valueAsString;

var v2 = this.getField("Radio Button 2").valueAsString;

var v3 = this.getField("Radio Button 3").valueAsString;

if (v1=="Off" || v2=="Off" || v3=="Off") event.value = "";

else {

    var total = Number(v1) + Number(v2) + Number(v3);

    if (total>0) {

        event.value = "Positive";

    } else event.value = "Negative";

}

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 ,
Jun 02, 2019 Jun 02, 2019
LATEST

Thanks MVP,

That works perfectly! Thanks to Maxwyss too, I don't know where I would have found that a default radio button is "Off".

Cheers!,

Bob

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