- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2022 01:32 PM
We have 4 fields in which only 1 field should be entered for example if the user provides value in GIft and then enter project ,we have a client script on change where it will clear the gift value and show an error message like below, but it will still show the error message , how to clear that ,
FYI : we have 4 onchange client scripts when the filed value changes, it will clear the values in the other fields and display the error message. (the error messages are bit confusing to user)
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2022 03:52 PM
Created 4 variables named "gift", "grant", "designated", and "project".
1. Client Script onChange on "gift"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldName = 'gift';
var columnNameList = ['gift', 'grant', 'designated', 'project'];
var sum = 0;
for (var i = 0; i < columnNameList.length; i++) {
sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
}
if (sum > 1) {
g_form.showFieldMsg(fieldName, 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
for (var j = 0; j < columnNameList.length; j++) {
if (columnNameList[j] != fieldName) {
g_form.hideFieldMsg(columnNameList[j]);
}
}
}
}
2. Client Script onChange on "grant"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldName = 'grant';
var columnNameList = ['gift', 'grant', 'designated', 'project'];
var sum = 0;
for (var i = 0; i < columnNameList.length; i++) {
sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
}
if (sum > 1) {
g_form.showFieldMsg('grant', 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
for (var j = 0; j < columnNameList.length; j++) {
if (columnNameList[j] != fieldName) {
g_form.hideFieldMsg(columnNameList[j]);
}
}
}
}
3. Client Script onChange on "designated"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldName = 'designated';
var columnNameList = ['gift', 'grant', 'designated', 'project'];
var sum = 0;
for (var i = 0; i < columnNameList.length; i++) {
sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
}
if (sum > 1) {
g_form.showFieldMsg(fieldName, 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
for (var j = 0; j < columnNameList.length; j++) {
if (columnNameList[j] != fieldName) {
g_form.hideFieldMsg(columnNameList[j]);
}
}
}
}
4. Client Script onChange on "project"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldName = 'project';
var columnNameList = ['gift', 'grant', 'designated', 'project'];
var sum = 0;
for (var i = 0; i < columnNameList.length; i++) {
sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
}
if (sum > 1) {
g_form.showFieldMsg(fieldName, 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
for (var j = 0; j < columnNameList.length; j++) {
if (columnNameList[j] != fieldName) {
g_form.hideFieldMsg(columnNameList[j]);
}
}
}
}
Execution result:
1. Enter Gift
2. Enter Designated
3. Enter Project
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2022 03:13 PM
These seem like informational messages- why not use these as help text- and you have the option- Always expanded- this way you dont have to fight with all of these client scripts.
If you must keep the client scripts- then you may have to add the line of code to clear the other 3 values on change just in case they have anything in them- but you have to do it for each script- add the clearing of the other 3 errors.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2022 03:52 PM
Created 4 variables named "gift", "grant", "designated", and "project".
1. Client Script onChange on "gift"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldName = 'gift';
var columnNameList = ['gift', 'grant', 'designated', 'project'];
var sum = 0;
for (var i = 0; i < columnNameList.length; i++) {
sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
}
if (sum > 1) {
g_form.showFieldMsg(fieldName, 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
for (var j = 0; j < columnNameList.length; j++) {
if (columnNameList[j] != fieldName) {
g_form.hideFieldMsg(columnNameList[j]);
}
}
}
}
2. Client Script onChange on "grant"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldName = 'grant';
var columnNameList = ['gift', 'grant', 'designated', 'project'];
var sum = 0;
for (var i = 0; i < columnNameList.length; i++) {
sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
}
if (sum > 1) {
g_form.showFieldMsg('grant', 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
for (var j = 0; j < columnNameList.length; j++) {
if (columnNameList[j] != fieldName) {
g_form.hideFieldMsg(columnNameList[j]);
}
}
}
}
3. Client Script onChange on "designated"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldName = 'designated';
var columnNameList = ['gift', 'grant', 'designated', 'project'];
var sum = 0;
for (var i = 0; i < columnNameList.length; i++) {
sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
}
if (sum > 1) {
g_form.showFieldMsg(fieldName, 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
for (var j = 0; j < columnNameList.length; j++) {
if (columnNameList[j] != fieldName) {
g_form.hideFieldMsg(columnNameList[j]);
}
}
}
}
4. Client Script onChange on "project"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldName = 'project';
var columnNameList = ['gift', 'grant', 'designated', 'project'];
var sum = 0;
for (var i = 0; i < columnNameList.length; i++) {
sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
}
if (sum > 1) {
g_form.showFieldMsg(fieldName, 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
for (var j = 0; j < columnNameList.length; j++) {
if (columnNameList[j] != fieldName) {
g_form.hideFieldMsg(columnNameList[j]);
}
}
}
}
Execution result:
1. Enter Gift
2. Enter Designated
3. Enter Project