Combobox not selecting array number to populate txt field

Hello,

I am not able in the combobox below to populate a text field by selecting from the list. I belive the the issue occurs becuase of the getField("N").value = aQuotes[item]; not capturing the [item] number. If I type a number in the [] the correct note populates the text field.


//text box for Notes :
var name = "N";
var type = "text";

var location = [370, 560, 535, 590];
var x = this.addField(name, type, 0, location);
x.multiline = true;
x.textSize = 10;
x.textFont = font.Times;
x.charLimit = 76; // 76 only allows two lines of text


//combo box for notes
var name = "k";
var type = "combobox";

var location = [370, 602, 535, 590];
var k = this.addField(name, type, 0, location);
//k.editable = true;
k.setItems( [" ", "Traceability per QA1000", "Traceability per QA2000",]);
k.textSize = 8;
//k.fillColor = color.yellow;



(function () {

// Do nothing if not committed
if (event.willCommit) return;

// Set up an array to hold the individual text
var aQuotes = [];

// Populate the array with the paragraph text
aQuotes[0] = "BLANK"
aQuotes[1] = "Traceability per quality assurance Plan QA1000 Traceability."
aQuotes[2] = "Traceability per quality assurance Plan QA2000 Traceability."

// Get the selected item, which is the export value of the selected combo box item
var item = event.changeEx

// Display the text corresponding to the selected item in the text field
getField("N").value = aQuotes[item];

})();


Thank you.


John Coulston


7 Answers

Where is all of this code located?

What happens when you run this code?

A link to a sample form would be more helpful than the code.


George Kaiser   

The code is running in a java script, run from Action Wizard. You should be create a new action and past it as a java scrip to run it. i believe that the field is undefined as it dosnt know what the [item] number is from the combo box pick.


Drop down is working [item] not captured when clicking item.



Thanks



John Coulston   

Did the self defined function get added to the form?

If you manually add the self defined function where you think it should be placed, does it work as you expected?

The best way to debug script for an Action or batch process is to run the script through the JavaScript console and observe the results.

You might want to look at the field object's setAction method. Because your script has quotation marks within the script, you will need to make adjustments to get the quotation marks to be processed as part of the script being inserted.


George Kaiser   

If I run the script with getField("N").value = aQuotes[2] it returns Traceability per quality assurance Plan QA2000 Traceability. in the field N as would be expected.

When I run the script in the consol it returns "undefined" error which is most likely the [item].

This is my first script so everything is new, I will look into the quotation marks.

Thank you


John Coulston   

That code assumes that you've set up numeric export values that act as an index to the array, you you will simply need to modify your setItems statement to include the correct export values for each combo box item. For example:

k.setItems( [[" ", 0], ["Traceability per QA1000", 1], ["Traceability per QA2000", 2]]);


George Johnson   

Hello,

I hope everyone had a good Memorial Day.

I am still having difficulty wiht this scrip. I added the k.setItems( [[" ", 0], ["Traceability per quality assurance Plan QA1000 Traceability.", 1], ["Traceability per quality assurance Plan QA2000 Traceability.", 2]]); however; the N box still comes up as undefined. I appreciate all the help you have given so far.


//text box for Notes : set text to 9 and multi line
var name = "N";
var type = "text";

var location = [370, 560, 535, 590];
var x = this.addField(name, type, p, location);
x.multiline = true;
x.textSize = 10;
x.textFont = font.Times;
x.charLimit = 76; // only allow two lines of text ** ;

//combo box for notes
var name = "k";
var type = "combobox";

var location = [370, 602, 535, 590];
var k = this.addField(name, type, p, location);//p
k.editable = true;
k.setItems( [[" ", 0], ["Traceability per quality assurance Plan QA1000 Traceability.", 1], ["Traceability per quality assurance Plan QA2000 Traceability.", 2]]);
k.textSize = 8;
//k.fillColor = color.yellow;
k.editable = true;


(function () {

// Do nothing if not committed
if (event.willCommit) return;

// Set up an array to hold the individual text
var aQuotes = [];

// Populate the array with the paragraph text
aQuotes[0] = "BLANK"
aQuotes[1] = "Traceability per quality assurance Plan QA1000 Traceability."
aQuotes[2] = "Traceability per quality assurance Plan QA2000 Traceability."

// Get the selected item, which is the export value of the selected combo box item
var item = event.changeEx

// Display the text corresponding to the selected item in the text field
getField("N").value = aQuotes[item];

})();

Thank you,

John


John Coulston   

Again, if you are creating the fields and trying to add a custom keystroke script to the "combobox" field, you need to use the "setAction" method of the field object.

I am not sure you want to add the fields and script for each use of the form. This approach will only work if all users have Acrobat.


George Kaiser   


Please specify a reason: