I have tabular form where col1 and col2 are numbers, and col3 should contain the difference between col1 and col2.
col1 has already had data and col 1 is editable, based on change in col1, col3 data will dynamically change.
To achieve this I have used ajax callback
process and JavaScript
, But the problem is when the difference is 0.xx
-0.xx
, I am getting parsing error.
other values I am able to print in col3.
Declare
p_curr number;
p_prev number;
p_diff number;
Begin
p_prev := to_number(apex_application.g_x01);
p_curr := to_number(apex_application.g_x02);
SELECT p_curr - p_prev into p_diff
from dual;
-- return calculated value
sys.htp.p(p_diff);
End;
--JavaScript
function f_CALC_DIFF(pThis) {
var row_id = pThis.id.substr(4);
var s = $('#f18_'+row_id).val().replace(/[^\d.-]/g, '');
var curr = $(pThis).val().replace(/[^\d.-]/g, '');
if(!s){
var s= 0;
var prev = s;}
else{
var prev = s;}
apex.server.process
( "CALC_DIFF", { x01: prev, x02: curr },
{ success: function( pData ) {
$('#f23_'+row_id).val(pData);}}
);
}
Please suggest the solution for the above problem.
I'm using Oracle Apex version 4.2
Instead of using expensive AJAX call to database, use JavaScript.
function f_CALC_DIFF(pThis) {
var row_id = pThis.id.substr(4);
var s = $('#f18_'+row_id).val().replace(/[^\d.-]/g, '');
var curr = $(pThis).val().replace(/[^\d.-]/g, '');
if(!s){
var s= 0;
var prev = s;}
else{
var prev = s;}
var diff = 0;
diff = (curr - prev);
var n = diff.toFixed(2);
alert (n);
$('#f23_'+row_id).val(n);
// Please remove the AJAX call to database.
/*apex.server.process
( "CALC_DIFF", { x01: prev, x02: curr },
{ success: function( pData ) {
$('#f23_'+row_id).val(pData);}}
);
} */