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

Using combobox to apply values

Duniagdra
Registered: Sep 24 2008
Posts: 140
Answered

I'm using the following code that originated from an example file on this sight, "Programming Lists Part 1":

function SetRacialBonus()
{
var oASRTB = { 
              Dragonborn: [2,0,0,0,0,2],
              Dwarf: [0,2,0,0,2,0],
              Eladrin: [0,0,2,2,0,0],
              Elf: [0,0,2,0,2,0],
              Half_Elf: [0,2,0,0,0,2],
              Halfling: [0,0,2,0,0,2],
              Tiefling: [0,0,0,2,0,2],
};
   if(!event.willCommit)
   {
      var nSelExp = 0;
      if(!isNaN(event.changeEx))
        nSelExp = event.changeEx
 
      this.getField("Ability_STR_Race").value = nSelExpo;
      this.getField("Ability_CON_Race").value = nSelExpo[ASRTB][0];
      this.getField("Ability_DEX_Race").value = nSelExpo[ASRTB][1];
      this.getField("Ability_INT_Race").value = nSelExpo[ASRTB][2];
      this.getField("Ability_WIS_Race").value = nSelExpo[ASRTB][3];
      this.getField("Ability_WIS_Race").value = nSelExpo[ASRTB][4];
   }
}

While I'm not getting any errors, I'm also not seeing the values applied to the appropriate fields.

The script is document level and the function is set in the format tab as custom keystroke script. I copied the method in which the example demonstrated this use. Could someone please tell me where I went wrong in this?

Thanks in advance for any help that may be provided.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

My Product Information:
Acrobat Pro 8.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
The following line and the other similar lines do not make sense given the context:

this.getField("Ability_CON_Race").value = nSelExpo[ASRTB][0];

The variable nSelExp must be a number or string primitive: either the number zero or the export value of the selected combo box item, which is a string, even though isNaN may (but probably doesn't) think it's a number, since you're assigning it the value of event.changeEx, which is a string. You're then attempting to access a property (or index) of this variable (again, which is a number or string primitive) given by whatever value ASTRB is, which is not clear given the code you posted. This will almost certainly fail since nSelExp is either a number (zero) or a string, not an Object or Array. The variable oASRTB is the Object you defined, but this is not the same as the variable ASRTB you're attempting to use.

Since I don't know what you set the export values of the combo box items to, I'll have to guess that what you really want to do is something like:

function SetRacialBonus() { // Define an object associating a string with an array of six numbersvar oASRTB = {Dragonborn: [2, 0, 0, 0, 0, 2],Dwarf: [0, 2, 0, 0, 2, 0],Eladrin: [0, 0, 2, 2, 0, 0],Elf: [0, 0, 2, 0, 2, 0],Half_Elf: [0, 2, 0, 0, 0, 2],Halfling: [0, 0, 2, 0, 0, 2],Tiefling: [0, 0, 0, 2, 0, 2]}; if (!event.willCommit) { // Get export value if the selected itemvar selExp = event.changeEx; // Set these field values based on the value of the currently selected item// which should be equal to a property name of the oASRTB object defined above,// each of which is an array of six numbersgetField("Ability_STR_Race").value = oASRTB[selExp][0];getField("Ability_CON_Race").value = oASRTB[selExp][1];getField("Ability_DEX_Race").value = oASRTB[selExp][2];getField("Ability_INT_Race").value = oASRTB[selExp][3];getField("Ability_WIS_Race").value = oASRTB[selExp][4];getField("Ability_WIS_Race").value = oASRTB[selExp][5];}}

But it's a bit hard to say without more information.

George
Duniagdra
Registered: Sep 24 2008
Posts: 140
George_Johnson wrote:
The following line and the other similar lines do not make sense given the context:this.getField("Ability_CON_Race").value = nSelExpo[ASRTB][0];

The variable nSelExp must be a number or string primitive: either the number zero or the export value of the selected combo box item, which is a string, even though isNaN may (but probably doesn't) think it's a number, since you're assigning it the value of event.changeEx, which is a string. You're then attempting to access a property (or index) of this variable (again, which is a number or string primitive) given by whatever value ASTRB is, which is not clear given the code you posted. This will almost certainly fail since nSelExp is either a number (zero) or a string, not an Object or Array. The variable oASRTB is the Object you defined, but this is not the same as the variable ASRTB you're attempting to use.

Since I don't know what you set the export values of the combo box items to, I'll have to guess that what you really want to do is something like:

But it's a bit hard to say without more information.

George
George, thanks for a good guess. My combobox is set up as follows:

Item: Dragonborn
Export Value:
Item List:
Dragonborn
Dwarf
Eladrin
Elf
Half_Elf
Halfling
Human
Tiefling

I was not sure the purpose of the export value so I left it blank. If this is incorrect I'm open for suggestion. I'll have to add an array of 0's for the human since the human gains a floating bonus of 2 to any one stat.

Is there a way when selecting the human an alert or something can prompt the user to select one of the six stats and once done that stat has a 2 applied and the rest are 0?

[b]EDIT 11-1-08:[/b] After some searching I did come across this [url=http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=15495]thread[/url]. Is this something I could apply here and if so, how?

Again thanks for your time and help.
Jim

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
The purpose of an export value it to set the value of an item to something other and what is displayed to the user. Since your combo box items are not using export values, you do not need to use event.changeEx, but can use event.change instead, though it should not make a difference.

Regarding your other question, I'm not familiar enough with what you're doing to say much other than yes, you can do that. You'd have to show your revised code and we can suggest some modifications.

George
Duniagdra
Registered: Sep 24 2008
Posts: 140
George_Johnson wrote:
The purpose of an export value it to set the value of an item to something other and what is displayed to the user. Since your combo box items are not using export values, you do not need to use event.changeEx, but can use event.change instead, though it should not make a difference.
The only reason I used event.changeEx was because I got a format error and figured since the example used that I should, but is not needed apparently sice adding your code has it working.

George_Johnson wrote:
Regarding your other question, I'm not familiar enough with what you're doing to say much other than yes, you can do that. You'd have to show your revised code and we can suggest some modifications.George
Below is my beginning attempt at hacking my way through ideas I've found as linked to above:

function SetRacialBonus() { // Define an object associating a string with an array of six numbersvar oASRTB = {Dragonborn: [2, "", "", "", "", 2],Dwarf: ["", 2, "", "", 2, ""],Eladrin: ["", "", 2, 2, "", ""],Elf: ["", "", 2, "", 2, ""],Half_Elf: ["", 2, "", "", "", 2],Halfling: ["", "", 2, "", "", 2],Human: [if(getField("Race").value == "Human")app.response("Enter model after info");]Tiefling: ["", "", "", 2, "", 2],}; if (!event.willCommit) { // Set these field values based on the value of the currently selected item// which should be equal to a property name of the oASRTB object defined above,// each of which is an array of six numbersgetField("Ability_STR_Race").value = oASRTB[selExp][0];getField("Ability_CON_Race").value = oASRTB[selExp][1];getField("Ability_DEX_Race").value = oASRTB[selExp][2];getField("Ability_INT_Race").value = oASRTB[selExp][3];getField("Ability_WIS_Race").value = oASRTB[selExp][4];getField("Ability_CHA_Race").value = oASRTB[selExp][5];}}

What I'm trying to have happen is should the user select the race Human I need the user to be prompted to choose one of the six abilities that the +2 racial bonus would be applied to. Since the user could pick any one of the six I was thinking somehow to have an alert or some type of user interface, like the response mentioned in the link above, allowing the user to select Strength, Constitution, Dexterity, Intelligence, Wisdom, or Charisma and upon making this selection commit a 2 to that specific field and 0's to the remaining fields, or leave them blank too, that will work as well.

In short, as you can see by the array above, my feeble attempt won't work because of syntax and I have no idea if I'm even going in the right direction. All I really need is once the user selects Human for them to be prompted to choose one of the six abilities.

I'm like a blind man in a mine field. I can kind of feel my way around, but I'm sure to blow it eventually.

In this line:
[b]
Human: [if(getField("Race").value == "Human")
app.response("Enter model after info");]
[/b]
"Enter model after info" is what was existing and I just copied it. I was going to first get acrobat to accept the code without giving errors and then figure how to give the user options of abilities to choose from.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

Duniagdra
Registered: Sep 24 2008
Posts: 140
Duniagdra wrote:
George_Johnson wrote:
The purpose of an export value it to set the value of an item to something other and what is displayed to the user. Since your combo box items are not using export values, you do not need to use event.changeEx, but can use event.change instead, though it should not make a difference.
The only reason I used event.changeEx was because I got a format error and figured since the example used that I should, but is not needed apparently sice adding your code has it working.

George_Johnson wrote:
Regarding your other question, I'm not familiar enough with what you're doing to say much other than yes, you can do that. You'd have to show your revised code and we can suggest some modifications.George
Below is my beginning attempt at hacking my way through ideas I've found as linked to above:

function SetRacialBonus() { // Define an object associating a string with an array of six numbersvar oASRTB = {Dragonborn: [2, "", "", "", "", 2],Dwarf: ["", 2, "", "", 2, ""],Eladrin: ["", "", 2, 2, "", ""],Elf: ["", "", 2, "", 2, ""],Half_Elf: ["", 2, "", "", "", 2],Halfling: ["", "", 2, "", "", 2],Human: [if(getField("Race").value == "Human")app.response("Enter model after info");]Tiefling: ["", "", "", 2, "", 2],}; if (!event.willCommit) { // Set these field values based on the value of the currently selected item// which should be equal to a property name of the oASRTB object defined above,// each of which is an array of six numbersgetField("Ability_STR_Race").value = oASRTB[selExp][0];getField("Ability_CON_Race").value = oASRTB[selExp][1];getField("Ability_DEX_Race").value = oASRTB[selExp][2];getField("Ability_INT_Race").value = oASRTB[selExp][3];getField("Ability_WIS_Race").value = oASRTB[selExp][4];getField("Ability_CHA_Race").value = oASRTB[selExp][5];}}

What I'm trying to have happen is should the user select the race Human I need the user to be prompted to choose one of the six abilities that the +2 racial bonus would be applied to. Since the user could pick any one of the six I was thinking somehow to have an alert or some type of user interface, like the response mentioned in the link above, allowing the user to select Strength, Constitution, Dexterity, Intelligence, Wisdom, or Charisma and upon making this selection commit a 2 to that specific field and 0's to the remaining fields, or leave them blank too, that will work as well.

In short, as you can see by the array above, my feeble attempt won't work because of syntax and I have no idea if I'm even going in the right direction. All I really need is once the user selects Human for them to be prompted to choose one of the six abilities.

I'm like a blind man in a mine field. I can kind of feel my way around, but I'm sure to blow it eventually.

In this line:
[b]
Human: [if(getField("Race").value == "Human")
app.response("Enter model after info");]
[/b]
"Enter model after info" is what was existing and I just copied it. I was going to first get acrobat to accept the code without giving errors and then figure how to give the user options of abilities to choose from.
I don't mean to push, just to bring this back to attention as needing help. Was I even close to hacking this right?

Ultimately a user interface would come up probably as radio options for STR CON DEX INT WIS and CHA and apply 2 to the corresponding field; Ability_STR_Race or Ability_CON_Race or Ability_DEX_Race etc.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack