IF statments in Adobe Acrobat DC

New Here ,
Jul 28, 2020

Copy link to clipboard

Copied

Hi all,

I’ve created my first fillable pdf by using the form function. I am new to this Javascript so I was wondering is there a way of automatically displaying a letter which corresponds to the mark. e.g A=5, B=4, C=3, D=2, E=1 and F=0.

So when I enter 3 in the marks column it will automatically display C in the grade column. I believe it’s a series of IF statement but not sure how to apply it in the field.

 

Thanking you in advance.

TOPICS
How to, PDF forms

Views

66

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

You can use something like this in your "Grade" field as custom calculation script.

 

var v = this.getField("Mark").valueAsString;
if (v == ""){
   this.getField("Grade").value = "";
}
if (v == "0"){
   this.getField("Grade").value = "F";
}
if (v == "1"){
   this.getField("Grade").value = "E";
}
if (v == "2"){
   this.getField("Grade").value = "D";
}
if (v == "3"){
   this.getField("Grade").value = "C";
}
if (v == "4"){
   this.getField("Grade").value = "B";
}
if (v == "5"){
   this.getField("Grade").value = "A";
}

 

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi,

 

There is nothing wrong with the above but you could also use a switch statement,

switch ( this.getField("Mark").valueAsString) {
case "0":
   this.getField("Grade").value = "F";
   break;
case "1":
   this.getField("Grade").value = "E";
    break;
case "2":
   this.getField("Grade").value = "D";
    break;
case "3":
   this.getField("Grade").value = "C";
    break;
case "4":
   this.getField("Grade").value = "B";
    break;
case "5":
   this.getField("Grade").value = "A";
    break;
default:
   this.getField("Grade").value = "";
   break
}

 

Regards

 

Malcolm

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thank you very much to both NesaNurani and BarlaeDC for taking your time and giving me such a timely response. I was wondering if I had a range of scores in each grade for example: F (1-3 marks) and E (4-5 marks) what would the syntax be?

 

Thanking you kindly.

 

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

If you mean to get F  when you write  1,2 or 3 then use like this (v == "1" || v == "2" || v == "3")

Likes

Translate

Translate

Report

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