Bringing up an alert with onChange client script

davilu
Mega Sage

I have two integer fields on a form and want an alert to show up if the sum of those two fields exceeds 6000.  I am trying to do this with an onChange client script that looks like this:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}

	var a = parseInt(g_form.getValue('field1'));
	var b = parseInt(g_form.getValue('field2'));
	if(a+b > 6000) {
		alert('Total cannot exceed 6,000.');
	}
}

What do I need to change in the above code in order for this to work?  Thanks!

1 ACCEPTED SOLUTION

Bhojraj Dhakate
Tera Expert

Hi davilu,

Please find below OnSubmit Client Script. It Working for me.

Code:

 

function onSubmit() {
//Type appropriate comment here, and begin script below
var strt = parseInt(g_form.getValue('a'));
var end =parseInt( g_form.getValue('b'));
var C = strt + end;
g_form.setValue('c',C);
if(C > 6000) {
alert('Total cannot exceed 6,000.');
return false;
}
else
return true;
}

Screenshot:

find_real_file.png

Thanks,

Bhojraj

View solution in original post

8 REPLIES 8

Jon Barnes
Kilo Sage

unless I am missing anything, your script looks fine to me. why don't you put some console.log statements in to check that you have good values for a and b.

console.log(a);

console.log(b);

and check your browser console for those results. are you getting good output there?

Bhojraj Dhakate
Tera Expert

Hi davilu,

Please find below OnSubmit Client Script. It Working for me.

Code:

 

function onSubmit() {
//Type appropriate comment here, and begin script below
var strt = parseInt(g_form.getValue('a'));
var end =parseInt( g_form.getValue('b'));
var C = strt + end;
g_form.setValue('c',C);
if(C > 6000) {
alert('Total cannot exceed 6,000.');
return false;
}
else
return true;
}

Screenshot:

find_real_file.png

Thanks,

Bhojraj

thanks raj! I used your code exactly and it still doesn't work.  our team is working in a scoped environment, not sure if that matters at all...

Have you created OnSubmit client Script...?

can you check all variable that you are passed in the client script ?

Thanks,

Bhojraj