Acrobat 9 Javascript Pulldown Menu if then

Community Beginner ,
Jan 24, 2019

Copy link to clipboard

Copied

Im building a spreadsheet for a gaming character sheet and Im having trouble implementing a javascript to do an "if-then command.

I have a pulldown list and I need a text field box to refer to which selection was made and then implement one math problem (adding up separate fields) or another.

For example under Race Pulldown there is Human or Halfling. If they pick Human then text field box needs to show the total calculation result of text field A+B. If it shows Halfling then it needs to show the result of text field A+C.

I tried using:

if (this.getField("Race Pulldown").value == "Halfling"){  

event.target.display = display.visible;

}

else{

event.target.display = display.hidden;

}

and replacing event.targeting.display with the math calculation but I couldnt get it to work

Thanks

Chad

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Try this code:

if (this.getField("Race Pulldown").value == "Halfling"){

    event.value = Number(this.getField("A").valueAsString) + Number(this.getField("C").valueAsString);

} else {

    event.value = Number(this.getField("A").valueAsString) + Number(this.getField("B").valueAsString);

}

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

137

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

Acrobat 9 Javascript Pulldown Menu if then

Community Beginner ,
Jan 24, 2019

Copy link to clipboard

Copied

Im building a spreadsheet for a gaming character sheet and Im having trouble implementing a javascript to do an "if-then command.

I have a pulldown list and I need a text field box to refer to which selection was made and then implement one math problem (adding up separate fields) or another.

For example under Race Pulldown there is Human or Halfling. If they pick Human then text field box needs to show the total calculation result of text field A+B. If it shows Halfling then it needs to show the result of text field A+C.

I tried using:

if (this.getField("Race Pulldown").value == "Halfling"){  

event.target.display = display.visible;

}

else{

event.target.display = display.hidden;

}

and replacing event.targeting.display with the math calculation but I couldnt get it to work

Thanks

Chad

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Try this code:

if (this.getField("Race Pulldown").value == "Halfling"){

    event.value = Number(this.getField("A").valueAsString) + Number(this.getField("C").valueAsString);

} else {

    event.value = Number(this.getField("A").valueAsString) + Number(this.getField("B").valueAsString);

}

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

138

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
Jan 24, 2019 0
Most Valuable Participant ,
Jan 24, 2019

Copy link to clipboard

Copied

Try this code:

if (this.getField("Race Pulldown").value == "Halfling"){

    event.value = Number(this.getField("A").valueAsString) + Number(this.getField("C").valueAsString);

} else {

    event.value = Number(this.getField("A").valueAsString) + Number(this.getField("B").valueAsString);

}

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...
Jan 24, 2019 0