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

Event.value with two subjects of instructions ...

hedrich
Registered: Nov 26 2008
Posts: 28

Hi,

is there a chance to modify the script below in that way, that there should be two subjects of instruction as a point of reference?

For example: Beside the "event.value == "Englisch" there should be one more condition to fill the field ("englisch") with the number 1. This could be - for example - a combination or the two subjects of instruction - may be English and Mathematics ??

The script :

if(event.value == "English")
{
this.getField("english").value = "1";
}

Kind Regards
Holger

try67
Expert
Registered: Oct 30 2008
Posts: 2399
You can add more conditions using the logical operator && , but an event can't have two values at the same time... Is this a multiple choice list? If not, you need to check the value of another field, like so:if((event.value == "English") && (this.getField("math").value=="math")) { ...

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

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
In the old school, one converts the field value to upper case or lower case before the comparison of the strings, when one can not control the value of a field or capitalization is not an issue.

// clear field// custom calculation script// field for which the language string is enteredthis.getField("english").value = "";// convert value string to lower case and compareif(event.value.toLowerCase() == "english"){this.getField("english").value = "1";}

For testing 2 fields in and placing the result in a third field, the custom calculation script for the 3rd field could be:

// get the value of the fields to compare in lower casevar sLanguage = this.getField('english').value.toLowerCase();var sMath = this.getField'math').value.toLowerCase();// test for both fields if(sLanguage == 'english' & sMath == 'geometry') {// action for both fields}// only english and not geometryif(sLanguage == 'english' & sMath != 'geometry') {// action for english only}// only  geometry and not englishif(sLanguage != 'english' & sMath == 'geometry') {// action for geometry only}// neither english or geometryif(sLanguage != 'english' & sMath != 'geometry') {// action for geometry only}

Another version of the above:
// get fields to comparevar sLanguage = this.getField('english').value.toLowerCase();var sMath = this.getField'math').value.toLowerCase();// test values  for both fields switch(true) {case (sLanguage == 'english' & sMath == 'geometry') :// action for both fieldsbreak; // end testing// test for english onlycase (sLanguage == 'english') :// action for english onlybreak; // end testing// only  geometrycase (sMath == 'geometry') :// action for geometry onlybreak; // end testing// all other valuesdefault:// action for none of the abovebreak;} // end switch choices

The alternative option allows for very complex relationships and one only needs to get the order of the testing correct.

George Kaiser