Dynamically set the value of fieldB based on the input in fieldA
Confluence User - 25 Feb, 2024
Hi I am new to Joget. How to create a field whose value is based on the value that the user inputs in another field? For example, if the user input in fieldA is 10 then fieldB is A10, if fieldA is 20 then fieldB is B20. Where should I put client-side JavaScript? How could I do that? Is there any tutor? Thanks.
function validate()
{
var result = true;
// Get the value of Field A
var fieldAId = "fieldA"; // Replace with the actual ID of Field A
var fieldA = FormUtil.getField(fieldAId);
if (fieldA != null) {
var fieldValue = $(fieldA).val();
// Set the value of Field B based on the input in Field A
var fieldBId = "fieldB"; // Replace with the actual ID of Field B
var fieldB = FormUtil.getField(fieldBId);
if (fieldB != null) {
var fieldBValue;
if (fieldValue === "10") {
fieldBValue = "Aa";
} else if (fieldValue === "20") {
fieldBValue = "Bb";
} else {
fieldBValue = ""; // Set a default value or leave it empty if no conditions are met
}
$(fieldB).val(fieldBValue);
}
}
return result;
}
forms