Page 1 of 1

Uncaught ReferenceError: calcAll is not defined

Posted: 02 Aug 2017
by smithme
Why am I getting the following error:
Uncaught ReferenceError: calcAll is not defined

calcAll is defined in the Javascript window for the form.
It is called from the OnClick of the Save button (buttons turned on).

**** Javascript ****

Code: Select all

function convertDecimalToDegree(data) {
	data.degree = Math(Math.trunc(data.decimal));
	data.minutes = Math.abs((data.decimal - Math.trunc(data.decimal))*60);
	data.seconds = (data.minutes - Math.trunc(data.minutes))*60;
}

function calcLatitude(){
	var data = {"decimal" : fd.field("GpsLatitude").value(),
	            "degree" : 0,
				"minutes" : 0,
				"seconds" : 0};
	convertDecimalToDegree(data);
	var compass = data.decimal < 0 ? "S" : "N";
	var text = data.degree + '°' + data.minutes.toFixed(1) + "'" + data.seconds.toFixed(1) + '"' + compass;	
	fd.field("GpsLatitudeText").value(text);
}

function calcLongitude(){
	var data = {"decimal" : fd.field("GpsLongitude").value(),
	            "degree" : 0,
				"minutes" : 0,
				"seconds" : 0};
	convertDecimalToDegree(data);
	var compass = data.decimal < 0 ? "W" : "E";
	var text = data.degree + '°' + data.minutes.toFixed(1) + "'" + data.seconds.toFixed(1) + '"' + compass;	
	fd.field("GpsLongitudeText").value(text);
}

function calcAll(){
	calcLatitude();
	calcLongitude();
}

**** Save OnClick ****

Code: Select all

calcAll();

Re: Uncaught ReferenceError: calcAll is not defined

Posted: 02 Aug 2017
by Nikita Kurguzov
Run this code inside JS editor instead:

Code: Select all

fd.onsubmit(function(){
    calcAll();
    return true;
});
Or something along these lines.
It is important to return true to save the form. But if you don't want to save item yet, simply return false.