make multiple fields able to be manually edited after receiving value from Java Script Calculation
Hello, I'm new and still learning in creating PDF forms using Java Script Calculation. I'm in the process to create a form with fields that have multiple Java Script codes to give an output based on individual/multiple input fields for examples the codes are as follow:
Java Script Code for output field 1:
var field1Value = this.getField("text10").value;
var field2Value = this.getField("Dropdown1").value;
if(field1Value == 0)
this.getField("Exchange for").value = " ";
else
this.getField("Exchange for").value = util.printf("%,0.2f",field1Value) + " " + field2Value;
Java Script for output field 2 which functions that output field 2 will shows words based on which checkboxes chosen on previous field:
var u = this.getField("Group3").value;
if(u != "2")
{this.getField("At").value = "Sight";
} else
if(u != "1")
{this.getField("At").value = "Usance";
} else
{this.getField("At").value == Null;
}
Java Script for output field 3 which functions to convert number inputted on input field into words:
// Field-level script for 'text10'
{
var text10Value = event.target.value;
var dropdown1Value = this.getField("Dropdown1").value;
var resultField = this.getField("At the Sum of 1");
if (text10Value == 0 || text10Value === "") {
resultField.value = " ";
} else {
resultField.value = ConvertToWords(text10Value) + " " + dropdown1Value;
}
};
of all the codes I mentioned above, all works fine individually, however my form have additional requirement where all of the output fields (output field 1, output field 2, output field 3) have to be able to be manually edited without changing the values or revert to values calculated by Java Script code from values of the source/input field. i have tried using this code on my output fields to enable manual edit on all of my output fields:
// Disable auto-update for 'At the Sum of 1'
this.getField("At the Sum of 1").setAction("Keystroke", "event.rc = true;");
// Function to set keystroke action for multiple fields
function setKeystrokeActionForFields(fieldNames) {
for (var i = 0; i < fieldNames.length; i++) {
var fieldName = fieldNames[i];
var field = this.getField(fieldName);
if (field) {
field.setAction("Keystroke", "event.rc = true;");
} else {
console.warn("Field '" + fieldName + "' not found.");
}
}
}
// Call the function and pass an array of field names
setKeystrokeActionForFields(["Exchange for", "At", "At the Sum of 1"]);
however the code above only work if i only manually edit 1 output field, if i try to edit the value of another output field the previous edited output field will revert back into values based on Java Script calculation of the input field, i needed the output field to be editable for print purposes while also so the output fields will give values if the input on the input fields changes. please help me regarding how to do that?
sorry for the long questions, i tried to describe it as detailed as possible to prevent ambiguity, and as i didnt really understand regarding Java Script, all the codes above are the result of surfing this forum.
thanks in advance!