简体   繁体   中英

Trying to write a simple script for work in Adobe Acrobat Pro

I'll start off by saying that I have no experience in JavaScript. What I've "learned" for this script is from 10 minutes of googling.

I have two form fields, named 'Section Width' (SW) and 'Insp Unit Width' (IUW) that are whole numbers. I'm trying to get IUW to equal SW if SW is less than or equal to 40. If SW is greater than 40 I need IUW to be half of SW to the next whole number. This is what I've come up with so far:

var SW = this.getField("Section Width").value;
var IUW = this.getField("Insp Unit Width");
if (SW <= 40){
    IUW = SW;
}, else {
    IUW = 0.5*SW;
}

Can someone please briefly educate me or point me to where I can learn how to make this work?

Try this:

const SW = this.getField("Section Width").value;

const IUW = (SW <= 40) ? SW : Math.ceil(0.5*SW);

Since you're ignoring the value of the IUW field, you don't need to do the IUW = this.getField("Insp Unit Width") part. Although, perhaps you need a reference to that field because you're going to update the field later... If that's the case, try:

const SW = this.getField("Section Width").value;

const IUW = (SW <= 40) ? SW : Math.ceil(0.5*SW);

const IUWField = this.getField("Insp Unit Width");

IUWField.value = IUW;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM