These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

If Then Else Combo Box

paulaeddy
Registered: May 14 2010
Posts: 22
Answered

I am attempting to populate a text field based on a combo box.
 
If ComboBox = Outstanding, TextField = 4
If ComboBox = Exceeds, TextField = 3
If ComboBox = Satisfactory, TextField = 2
If ComboBox = Marginal, TextField = 1
Else Text Field = 0
 
This is what I have so far (after multiple attempts).
 
var rating = this.getField("ComboBox7").value;
if( rating = "Outstanding" )
event.value = 4;
else if( rating = "Exceeds" )
event.value = 3;
else if( rating = "Satisfactory" )
event.value = 2;
else if( rating = "Marginal" )
event.value = 1;
else
event.value = 0;
 
Thank you for your help!

My Product Information:
Acrobat Pro 9.4.2, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The comparison operator is "==", not "=".

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
I find setting the "Export value" for an option in a combo box or drop down box reduces the code for the text field to just setting the text field value to the value of the combo box or drop down box.

event.value = this.getField("ComboBox7").value

One could even set the value of the text field by using the "custom keystroke" or the "on blur action".

George Kaiser

paulaeddy
Registered: May 14 2010
Posts: 22
Thank you! This helps! One more question regarding this scenario...if I were to turn the variables around, how could I tell it a range?

Example:

var rating = this.getField("ComboBox7").value;
if( rating = "3.5 - 4" )
event.value = Outstanding;
else if( rating = "2.5 - 3.49" )
event.value = Exceeds;
else if( rating = "1.5 - 2.49" )
event.value = Satisfactory;
else if( rating = ".5 - 1.49" )
event.value = Marginal;
else
event.value = Unsatisfactory;

paulaeddy
Registered: May 14 2010
Posts: 22
Oh, nevermind! I got it...

var rating = this.getField("ComboBox7").value;
if( rating >= 3.5 )
event.value = Outstanding;
else if( rating >= 2.5 )
event.value = Exceeds;
else if( rating >= 1.5 )
event.value = Satisfactory;
else if( rating >= .5 )
event.value = Marginal;
else
event.value = Unsatisfactory;


try67
Expert
Registered: Oct 30 2008
Posts: 2398
You still need to place all the strings between double-quotes.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Accepted Answer
You might want to look at the MDC JavaScript Reference.The numeric comparative operators are

< - Less Than
<= - Less Than or Equal to
== - Equal
=== - Strict Equal
>= - Greater Than or Equal to
> - Greater Than
!= - Not Equal

The logical operators are:

&& - logical AND
|| - Logical OR
! - Logical NOT

Sting value starting with alphabetical characters need to be within matched quotation marks. Numeric value should not be between quotation marks.

So your script could be written as:

var rating = this.getField("ComboBox7").value;
if( rating >= 3.5 && rating <= 4)
event.value = "Outstanding";
else if(rating >= 2.5 && rating < 3.5)
event.value = "Exceeds";
else if( rating >= 1.5 && rating < 2.5 )
event.value = "Satisfactory";
else if( rating >= .5 && rating < 1.5 )
event.value = "Marginal";
else
event.value = "Unsatisfactory";


Without nested if statements:

var rating = this.getField("ComboBox7").value;
if(rating >= 3.5 )
event.value = 'Outstanding';
if(rating >= 2.5 && rating < 3.5)
event.value = 'Exceeds';
if(rating >= 1.5 && rating < 2.5)
event.value = 'Satisfactory';
if(rating >= 0.5 && rating < 1.5)
event.value = 'Marginal';
if(rating < 0.5)
event.value = 'Unsatisfactory';



You could also use the 'switch' statement:

var rating = this.getField("ComboBox7").value;
switch(true) {
case (rating.toString() == ' '):
event.value = '';
break; // end further testing
case (rating >= 0 && rating < 0.5):
event.value = 'Unsatisfactory';
break; // end further testing
case ( rating >= 0.5 && rating < 1.5 ):
event.value = 'Marginal';
break; // end further testing
case (rating < 2.5 ):
event.value = 'Satisfactory';
break; // end further testing
case (rating < 3.5 ):
event.value = 'Exceeds';
break; // end further testing
case(rating <= 4):
event.value = 'Outstanding';
break; // end further testing
default:
event.value = '';
break;
}



George Kaiser

acrobatragu
Registered: Mar 9 2011
Posts: 1
Hi, could anyone please help me write a javascript for adobe acrobat.

this is scenario.

I have yes and no checkboxes and field
when yes is clicked I want a number 1000 to appear in the field
and another number 0 when no clicked.