Copy link to clipboard
Copied
Hello, everyone. im trying to add a formula to a box depending on the value of a check box. I did it this way, but it is not working. Can someone please help
if (this.getField("FHAboxcal").value!="Off") event.value=(PropertyValue-(PropertyValue*Down/100))
;
else if (this.getField("FHAboxcal").value!="On") event.value=((PropertyValue-(PropertyValue*Down/100))+( (PropertyValue-(PropertyValue*Down/100))
*(1.75/100)))
;
Try this:
var pv = Number(this.getField("PropertyValue").valueAsString);
var d = Number(this.getField("Down").valueAsString);
var cb = this.getField("FHAboxcal").valueAsString;
if(pv && d){
if (cb != "Off")
event.value = pv-(pv*d/100);
else if (cb == "Off")
event.value =((pv-(pv*d/100))+((pv-(pv*d/100))
*(1.75/100)));}
else
event.value = "";
The error is in this line:
var d = c-((c*b/100)));
You have one too many closing brackets. Use this:
var d = c-(c*b/100);
Copy link to clipboard
Copied
Are 'PropertyValue' and 'Down' field names?
If yes, you also need to use this.getField() to get their values, same as you did for checkbox.
For 'else if' part, if you added export value to be 'On' it's ok if not, check that value is equal to "Off".
Copy link to clipboard
Copied
Thank you so much. Do you mean something like this?
var a = Number(this.getField("FHAboxcal").value);
var b = Number(this.getField("Down").value);
var c = Number(this.getField("PropertyValue").value);
var d = PropertyValue-(PropertyValue*Down/100)
*(1.75/100);
var e= PropertyValue-(PropertyValue*Down/100);
var total = if (this.getField("a").value!="Off") event.value=e;
else if (this.getField("a").value!="On") event.value=d
;;
if(a == "" || ir == "" || lt == "")
event.value = "";
else
event.value = total;
Copy link to clipboard
Copied
It's giving me an error anyway =(
Copy link to clipboard
Copied
You doesn't use the variables b and c.
Copy link to clipboard
Copied
Thank you i corrected but still gives me an
"SyntaxError: syntax.error6:at line7
do you have any Ideas?
Copy link to clipboard
Copied
Sorry now looks liked this
var b = Number(this.getField("Down").value);
var c = Number(this.getField("PropertyValue").value);
var d = c-(c*b/100)*(1.75/100);
var e= d-(d*Down/100);
var total = if (this.getField("a").value!="Off") event.value=e;
else if (this.getField("a").value!="On") event.value=d
;;
if(a == "" || ir == "" || lt == "")
event.value = "";
else
event.value = total;
and still give a syntax error
Copy link to clipboard
Copied
This line doesn't make any sense:
var total = if (this.getField("a").value!="Off") event.value=e;
You also have a bunch of logical errors in your code.
Copy link to clipboard
Copied
Thank you for your input. Im trying to to condition if "box FHbox" is checked to do "d" if not, to do "e" I know it must be annoying sorry for that, and thank you so much for your input i have cleaned it as much as I can +
var a = Number(this.getField("FHAboxcal").value);
var a = Number(this.getField("FHAboxcal").value);
var b = Number(this.getField("Down").value);
var c = Number(this.getField("PropertyValue").value);
var d = c-((c*b/100)*(1.75/100));
var e= d-(d*Down/100);
var total = if (this.getField("a").value!="Off") event.value=e;
else if (this.getField("a").value!="On") event.value=d
;;
if(a == "" || b == "" || c == "")
event.value = "";
else
event.value = total;
Copy link to clipboard
Copied
I think you mean this:
var total;
if (this.getField("a").value=="Off") total = d;
else total = e;
Copy link to clipboard
Copied
thank you so very much makes way more sense than mine, although still is giving me this
Copy link to clipboard
Copied
I'm not getting any syntax errors, although you should remove one of the double semi-colons.
Post your code as text, not an image.
Copy link to clipboard
Copied
try67. I appreciate your help on this one. I changed it to a simpler way, and it still gives me an error now in "var e = " I know that I have been a pain in the butt please take a last look I appreciate it:
var a = Number(this.getField("FHAboxcal").value);
var b = Number(this.getField("Down").value);
var c = Number(this.getField("PropertyValue").value);
var d = c-((c*b/100)));
var e = d*0.0175;
var f = d+e
var total = if (this.getField("a").value=="Off") total = d;
else total = f;
;;
if(a == "" || b == "" || c == "")
event.value = "";
else
event.value = total;
Copy link to clipboard
Copied
Try this:
var pv = Number(this.getField("PropertyValue").valueAsString);
var d = Number(this.getField("Down").valueAsString);
var cb = this.getField("FHAboxcal").valueAsString;
if(pv && d){
if (cb != "Off")
event.value = pv-(pv*d/100);
else if (cb == "Off")
event.value =((pv-(pv*d/100))+((pv-(pv*d/100))
*(1.75/100)));}
else
event.value = "";
Copy link to clipboard
Copied
Thank you for taking the time to help me. You are very kind. It works great !!!
Copy link to clipboard
Copied
The error is in this line:
var d = c-((c*b/100)));
You have one too many closing brackets. Use this:
var d = c-(c*b/100);
Copy link to clipboard
Copied
Thank you for your observation. It also works perfectly. I appreciate your time and effort.
Thank you for helping me to grow in this field till next time,