Highlighted

script help - setting initial values

New Here ,
Jun 01, 2019

Copy link to clipboard

Copied

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

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

}

Topics

PDF forms, Windows

Views

408

Likes

Translate

Translate

Report

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

script help - setting initial values

New Here ,
Jun 01, 2019

Copy link to clipboard

Copied

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

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

}

Topics

PDF forms, Windows

Views

409

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Advocate ,
Jun 02, 2019

Copy link to clipboard

Copied

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".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Jun 02, 2019

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jun 02, 2019

Copy link to clipboard

Copied

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

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Jun 02, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF
Add a group