Hi @anefarious1,
Yes of course, that’s possible, for example, assuming that the field for weight is the fieldname1, and that the equation result is the number 0.5 if the weight is greater than 100, and the text: “Do not Take This Medication” in others cases, the equation would be as simple as:
(function(){
if(fieldname1 <= 100 ) return 'Do not Take This Medication';
else return 0.5;
})()
But what happen if the text is longer than the calculated field’s size? in this case I recommend you an alternative solution:
– Insert a “HTML Content” field in the form, with the piece of code below as its content:
<div class="my-result"></div>
– And then, modify the equation as follows:
(function(){
var r = 0.5;
if(fieldname1 <= 100 ) r = 'Do not Take This Medication';
jQuery('.my-result').html(r);
})()
Tip: In this case, as the calculated field is used as an auxiliary field, I recommend you tick the checkbox: “Hide Field From Public Page”
Best regards.
It’s very helpful. Thanks!
A follow up on this if you don’t mind… Your solution works but the substituted message displays before the user inputs any value. How can I set it up so the ‘zero equivalent’ message displays only after a certain value is input? Thanks
Hi,
In this case you should use a conditional statement in the equation, similar to the following one:
(function(){
if(fieldname1)
{
if(fieldname1 <= 100 ) return 'Do not Take This Medication';
else return 0.5;
}
return '';
})()
Best regards.
That works but is there a way to hide the value I’m using for “Symbol to display at the end of calculated field”, when the result is the zero equivalent? It doesn’t apply when my zero equivalent is displayed for users.
Hi,
If you don’t want to display the currency symbol when the result is zero, you should to include the currency symbol from the equation instead of field’s attributes.
For example, leaving in blank the attributes of the calculated field, and then, if the equation is: fieldname1+fieldname2
, modify it as follows:
(function(){
var r = fieldname1+fieldname2;
if(r) return '$'+r;
return '';
})()
Best regards.
Sorry. I can’t figure out how to incorporate “var r” into the following:
(function(){
if(fieldname9)
{
if(fieldname9 <= 100 ) return ‘Body weight too low’;
else return ROUND((fieldname9*0.75)/5)*5;
}
return ”;
})()
I want to add “milligrams” for results that aren’t zero and “Body weight too low” for results of zero. Sorry to take up your time.
Hi,
In this case the equation would be as simple as follows:
(function(){
if(fieldname9)
{
if(fieldname9 <= 100 ) return 'Body weight too low';
else{
var r = ROUND((fieldname9*0.75)/5)*5;
return (r) ? r + ' milligrams' : '';
}
}
return '';
})()
Best regards.
Perfect. You are a wizard. Thanks!