For example:
I’m having an item :P1_SALES
And I want to enter 1000+2000-1000
And it will give me 2,000 on the same item :P1_SALES
Note I’m using a plug-in(AutoNumeric) for my input format
❇️ OrclQA.Com is a question and answer forum for programmers.
❇️ Here anyone can ask questions and anyone can answer to help others.
❇️ It hardly takes a minute to sign up and it is 100% FREE.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Vinish Kapoor
To do this, create a dynamic action on P1_SALES on Lose Focus event and create a true action to execute JavaScript code as follows:
Save the changes and test.
Bansari
Thank you so much for quick response.
This is working perfectly fine.
Just one thing is that I couldn’t implement it with AutoNumeric Plug-in.
It’s provide only one number input, whenever I try to input 2 numbers with + or - sign it is taking it as a negative positive number differentiation.
And I really need that plug-in in order have flexibility for number format.
Can anyone please help me with it.
Vinish Kapoor
You can use the Text Field item instead of Numeric and disable the AutoNumeric for this field and use the below expression in the Text Field item's > Advance > Custom Attributes section:
The above expression will format the number.
Bansari
Hello,
thanks, for the solution.
Now everything is working step by step.
I'm right now on the last step of fulfilling the requirement.
I did apply both above step and using this now the last part is addition of 2 fields with the same behavior I mentioned above.
I used JavaScript solution of yours' (https://www.foxinfotech.in/2020/02/oracle-apex-calculate-field-values-using-javascript.html)
But now all three fields working differently:
1. P1_SALES, P1_COST (TEXTFIELD with 2 steps mentioned above)
2. P1_PROFIT (TEXTFIELD with JavaScript solution mentioned in this message with link) - Formula set in JS (P1_SALES - P1_COST)
Now when trying to input in P1_SALES: 1000+2000
it gives 3000 in P1_PROFIT
but when I did put 1000 in P1_COST
it gives 1000(which is taking P1_COST value only) in P1_PROFIT and set P1_SALES to 0
Please advise
Vinish Kapoor
Your JS function should be as below:
Now call the above function fnc_calcTotal from P1_sales and P1_cost on lose focus event.
Bansari
Yes I do have exact same function.
Just difference is, I do have input type 1000+2000 and function in same dynamic action.
Bansari
I guess because I'm using
onfocusout="this.value=Number(this.value).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')"
as well on both the fields
and then I do have 2 JS code implementing in dynamic action for both items.
Vinish Kapoor
Remove the onfocusout line from the custom attributes. I have added this line to the function. Now change the JS function as below and call it from P1_SALES and P1_COST:
Bansari
I tried below function
function fnc_calcTotal() {
var n_sales, n_cost, n_profit;
n_sales = eval($v("P11_SALES"));
$s("P11_SALES", n_sales);
n_cost = eval($v("P11_COST"));
$s("P11_COST", n_cost);
n_sales = parseFloat($v("P11_SALES"), 10) ? parseFloat($v("P11_SALES"), 10) : 0;
n_cost = parseFloat($v("P11_COST"), 10) ? parseFloat($v("P11_COST"), 10) : 0;
n_profit = n_sales - n_cost;
$s("P11_PROFIT", parseFloat(n_profit, 10));
}
Removed custom attribute and eval function from both P11_SALES and P11_COST as you mentioned
But, it is not giving me P11_PROFIT calculated and, Where can I add format part as I have to implement it?
Thanks
Vinish Kapoor
I have tested the above code and it is working completely fine.
After creating that function in Function and Global Variable declare section and I am simply calling it using dynamic action on losing focus event by executing the JS code as below:
Bansari
Ok, I can double check my function and fields,
But please let me know how to achieve format within those numbers as it is equal important for me with this arithmetic ability.
I have tried “ Number(this.value).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')"
within function.
Vinish Kapoor
We can specify the format to the P1_SALES, but it will be an issue in calculating values then.
Bansari
Yes, you are right, I tried but it’s not calculating values.
Is there any other way?
Format mask also not supporting.
And tried plug-ins too, but those ones are not allowing me to enter numbers like 1000-500.
Bansari
Please help me out to close this as it is getting crucial for my project.
Thanks in advance for all your extra effort.