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

Updating Field Values

pb
Registered: Jan 23 2009
Posts: 27

Hi,

I am relatively new to Acrobat Javascript and I am having a problem updating field values. I calculate values for 3 fields. I trigger Javascript to run on MouseDown. I have

var cResponse0 = app.Response(
{
cQuestion: "Enter value 3:",
cTitle: "Value 3 entry"
});

calcVal3 =cResponse0.toString();
this.getField("Field1").value = calcVal1;
this.getField("Field2").value = calcVal2;
this.getField("Field3").value = calcVal3;

My problem is that when the code is run, when I enter a value for cResponse0 the first time, all the Fields update correctly. If, however, I now go back and change the value of cResponse0, Field1 and Field2 update correctly but Field 3 (which has been changed to the correct value - I use app.alert() to check this) doesn not update until I click out of the field. I have been trying a number of things and have been working on this on my own for the last 2 days but I am not making any progress. Any help would be greatly appreciated. Thank you very much in advance.
Regards,
Paul

My Product Information:
Acrobat Pro 7.0
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Where exactly have you placed this code? You said you're using the Mouse Down event, but of which field?

Also, it should be "app.response", not "app.Response". In your code it's not clear where the calcVal1 and calcVal2 variables are getting set. Is this the complete code you're using? Why are you using "toString()"?

George
pb
Registered: Jan 23 2009
Posts: 27
Hi George,

Thank you very much for responding to my post. Here are the answers to the questions you ask:

1. The code is placed on the MouseDown action inside Field3.

2. Regarding app.Response, you are 100% correct. I checked my code and the code in fact uses app.response. I made a mistake when typing my first post. My apologies.

3. I am using toString() because cResponse0 is a contract number that the user inputs. I need to have it padded with zeros to a fixed length of 5 places (i.e. I input 998 and have it converted to 00998) and I display 00998 in Field3.

4. I am not sure how to answer the question about where the calcVal variables are being set because I am not sure what you are asking here. All the calcVal variables are calculated after the app.response() and before they are set. So here is a skeleton of the actual code:

//********
var contractLimit1 = contractLimit-1;
var contractNumberOption = null;
contractNumberOption = app.popUpMenu("Starting Number", "Number of Contracts");
if (contractNumberOption != null)
{
var tmpValue0 = null;
var tmpValue1 = null;
var tmpValue2 = null;
var str0 = "Specify the number of contracts, if necessary.\n\n";
var str1 = "The current number of contracts specified: ";
var str2 = "The current starting number for the contracts: ";
var str3 = "The current ending number for the contracts: ";

if (contractNumberOption == "Starting Number")
{
var cResponse0 = app.response(
{
cQuestion: "Please specify the starting number for the contracts:",
cTitle: "Contract Starting Number"
});
tmpValue0 = this.getField("NumberofContractsHolder").value;
tmpValue1 = this.getField("StartingNumberHolder").value;

var startNumber1 = cResponse0.toString();
if (cResponse0 < 10000) startNumber1 = "0"+cResponse0.toString();
if (cResponse0 < 1000) startNumber1 = "00"+cResponse0.toString();
if (cResponse0 < 100) startNumber1 = "000"+cResponse0.toString();
if (cResponse0 < 10) startNumber1 = "0000"+cResponse0.toString();
if (cResponse0 > contractLimit1 || cResponse0 < 1 || isNaN(cResponse0) ||
Math.floor(cResponse0) != Math.ceil(cResponse0) || cResponse0 == null)
{
startNumber1 = "?";
cResponse0 = -1;
}
if (tmpValue0 > contractLimit || tmpValue0 < 1 || isNaN(tmpValue0) ||
Math.floor(tmpValue0) != Math.ceil(tmpValue0) || tmpValue0 == null)
tmpValue0 = -1;
tmpValue2 = -1;
if (cResponse0 > 0 && tmpValue0 > 0) tmpValue2 = parseInt(cResponse0) + parseInt(tmpValue0);
var tmpValue21 = tmpValue2-1;
if (cResponse0 > -1 && tmpValue21 > contractLimit1)
{
tmpValue21 = contractLimit1;
var nContracts = tmpValue21-cResponse0+1;
this.getField("NumberofContractsHolder").value = nContracts;
this.getField("StartingNumberHolder").value = cResponse0;
this.getField("EndingNumberHolder").value = tmpValue21;
this.getField("ContractNumber").value = startNumber1;
//**** the above updates the fields in real time but if I go the change the field value (starting number)
//**** and the field has not lost focus, the code jumps to the next if (cResponse0 ..) code block
app.alert("The number of contracts has been reset to "+nContracts.toString()+
" to meet the "+ contractLimit1.toString()+
" restriction on the total number of contracts.");
}
var endNumber1 = tmpValue21.toString();
if (tmpValue21 < 10000) endNumber1 = "0"+tmpValue21.toString();
if (tmpValue21 < 1000) endNumber1 = "00"+tmpValue21.toString();
if (tmpValue21 < 100) endNumber1 = "000"+tmpValue21.toString();
if (tmpValue21 < 10) endNumber1 = "0000"+tmpValue21.toString();
if (tmpValue21 < 1) endNumber1 = "?";
var tmpValue01 = tmpValue0;
if (tmpValue0 == -1) tmpValue01 = "?";

if (cResponse0 > -1 && tmpValue21 < contractLimit)
{
//**** the code jumps here and only the first two fields update in real time. The contract number field,
//**** the third field and the field in which this code runs only gets updated once I click outside the field.
//**** It does not change when I make the change in the starting number.
this.getField("StartingNumberHolder").value = cResponse0;
this.getField("EndingNumberHolder").value = parseInt(tmpValue21);
this.getField("ContractNumber").value = startNumber1;
while (tmpValue0 < 1)
{
app.alert("Number of contracts must be greater than 0, and less than "+contractLimit.toString()+
......
//********

I hope this helps. Thank you very much for your help.
Regards,
Paul