Search code examples
javascriptformsacrobat

Return array for a field event | javascript | acrobat editor


I am trying to return an array for a dropdown change event. The code for custom keystroke script for a drop down is as follows:

if( event.willCommit )
{
   var array = this.Page1_FieldSet(3);  
}

The document-level javascript is as follows:

var Page1_array = {
	1: {val: 1},
	2: {val: 2},
	3: {val: 3}};

function Page1_FieldSet(i)
{
	var array = Page1_Array[i];
	return array;
}

I am trying to access the array Page1_Array on the change of a dropdown value in pdf form. On debugging I am getting the referencing error. Please help me with the correct code. Here's the error:

Error: ReferenceError: Page1_Array is not defined 15:Document-Level:Page1_FieldSet

Solution

  • Assuming you don't have scope issues...

    Here you're defining Page1_array:

    var Page1_array = {
    

    Notice the lowercase a in array.

    But here you're referencing Page1_Array:

    var array = Page1_Array[i];
    

    ...which is a different reference because of the uppercase A. Just change the A to a.