display a warning when going over a calculated amount
-
I have a slider field for annual turnover (fieldname16) and an amount to borrow (fieldname11) and I need a warning to appear if the amount to borrow is great than the turnover / 12 (a twelfth).
Can you explain how to do this please
Thankshttps://www.ads-software.com/plugins/calculated-fields-form/
-
Hi,
In this case I recommend you display an alert, from an equation associated to a calculated field in your form, using a snippet of code like follow:
if(fieldname11 > fieldname16/12 ) alert( ‘Your message here’ );
Tip: The previous code should be use as part of an equation with the format: (function(){…})()
Best regards.
Thanks for this, however the Tip has confused me.
So in a new calculation field (say, fieldname20) I put in the calculation with the alert: “if(fieldname11 > fieldname16/12 ) alert( ‘Your message here’ );”
But does that get incorporated somewhere else?
ThanksHi,
I guess you are using the values of fieldname11 and fieldname16 in your own equation, but you want limit the values entered by the users, in this case you simply should modify your current equation, similar to:
(function(){
if(fieldname11 > fieldname16/12 ){
alert( ‘Your message here’ );
return 0;
}
else
{
…
}
})()The … symbol should be replaced by the operations to be applied if the values of fieldname11 and fieldname16 are correct.
Best regards.
I’ve test this, but rather than an alert, can the message replace the resulting calculation?
So up to the point where fieldname11 is not > than fieldname216/12, I want it to display the result of the calculation, but over that point, to display the text ‘You can’t borrow this that much’Is this possible?
Hi,
Yes, of course but you should edit the previous equation like follow:
(function(){
if(fieldname11 > fieldname16/12 ){
reutrn “You can’t borrow this that much”;
}
else
{
…
}
})()Furthermore, you should modify the plugin’s code for accepting texts in the calculated fields. Please, read the answer to the question: “Q: How can be displayed texts in the calculated fields?” in the FAQ page of the plugin:
https://www.ads-software.com/plugins/calculated-fields-form/faq/
Best regards.
Oh, this is so frustrating.
Take a look at my screenshot: https://dl.dropboxusercontent.com/u/4556853/calculation-not-working.png
No matter whether the figure is above or below the limit, the calculation field does NOT display anything!!
Here’s the code that’s in the Monthly repayments field:
(function(){
if(fieldname11 > fieldname16/12 ){
reutrn “You can’t borrow this that much”;
}
else
{
prec(IF(IN(fieldname12,[3,4,5]),fieldname11*0.36,IF(IN(fieldname12,[6,7,8]),fieldname11*0.19,IF(IN(fieldname12,[9,10,11]),fieldname11*0.1333,IF(IN(fieldname12,[12,13,14,15,16,17]),fieldname11*0.105,IF(IN(fieldname12,[18,19,20,21,22,23]),fieldname11*0.0767,IF(IN(fieldname12,[24]),fieldname11*0.00625)))))),2)
}
})()I’ve spent hours on this, why isn’t it working??!!
ThanksOne thing is that you have misspelt “return” as “reutrn”.
Hi,
Thanks Vivanco, you are right.
Jowelboy you should return a value from the “else” section too, like follow:
(function(){ if(fieldname11 > fieldname16/12 ){ return "You can't borrow this that much"; } else { return prec(IF(IN(fieldname12,[3,4,5]),fieldname11*0.36,IF(IN(fieldname12,[6,7,8]),fieldname11*0.19,IF(IN(fieldname12,[9,10,11]),fieldname11*0.1333,IF(IN(fieldname12,[12,13,14,15,16,17]),fieldname11*0.105,IF(IN(fieldname12,[18,19,20,21,22,23]),fieldname11*0.0767,IF(IN(fieldname12,[24]),fieldname11*0.00625)))))),2); } })()
Thanks vivanco and Codepeople – I foolishly copy & pasted the original code with the spelling mistake.
So I added the extra ‘return’ as suggested. Now the calculation is showing correctly up to the point where the text has to be displayed and nothing is shown.
here’s the link: https://biznizcash.hedjam.net/limited-company-application/
here’s the screenshot showing no text: https://dl.dropboxusercontent.com/u/4556853/calc-not-displaying.png
here’s the code:[ Moderator note: Code fixed, please wrap code in backticks or use the code button. ]
(function(){ if(fieldname11 > fieldname16/12 ){ return "You can't borrow this that much"; } else { return prec(IF(IN(fieldname12,[3,4,5]),fieldname11*0.36,IF(IN(fieldname12,[6,7,8]),fieldname11*0.19,IF(IN(fieldname12,[9,10,11]),fieldname11*0.1333,IF(IN(fieldname12,[12,13,14,15,16,17]),fieldname11*0.105,IF(IN(fieldname12,[18,19,20,21,22,23]),fieldname11*0.0767,IF(IN(fieldname12,[24]),fieldname11*0.00625)))))),2); } })()
HELP???!!
Thought it might be the apostrophe in the text ‘can’t’ but without it, it still isn’t working.
Hi Jowelboy,
Have you followed the instructions to allow texts in the Calculated Fields? The calculated fields are designed to accept numeric values (resulting of mathematical operations) but if you want include texts in the calculated fields, please, read the answer to the question: “Q: How can be displayed texts in the calculated fields?” in the FAQ page of the plugin:
https://www.ads-software.com/plugins/calculated-fields-form/faq/
Best regards.
That works a charm!
Thanks for the help.Final question on this issue:
Currently there is a ‘insert before’ (a £ sign) and ‘insert after’ is the text ‘per month’.
Obviously when the calculation returns the text ‘You can’t borrow that much’ I’m actually getting: ‘£You can’t borrow that much permonth’.In the calculation can I add something like:
return “£” & PREC…. & “per month” rather than use the insert before / after?
If so, what would the synatax be?
ThanksHi,
In your particular case, you should remove the symbols from the calculated field settings, and include it directly in the equation:
[ Moderator note: Code fixed, please wrap code in backticks or use the code button. ]
(function(){ if(fieldname11 > fieldname16/12 ){ return "You can't borrow this that much"; } else { return '£' + prec(IF(IN(fieldname12,[3,4,5]),fieldname11*0.36,IF(IN(fieldname12,[6,7,8]),fieldname11*0.19,IF(IN(fieldname12,[9,10,11]),fieldname11*0.1333,IF(IN(fieldname12,[12,13,14,15,16,17]),fieldname11*0.105,IF(IN(fieldname12,[18,19,20,21,22,23]),fieldname11*0.0767,IF(IN(fieldname12,[24]),fieldname11*0.00625)))))),2) + ' per month'; } })()
Best regards.
- The topic ‘display a warning when going over a calculated amount’ is closed to new replies.