Copy link to clipboard
Copied
Hello,
I'm very beginner and have issues like in the subject. I have some troubles because I got something like this in my 'textbox2' but it doesnt work:
var a = this.getField("Text1");
var b = this.getField("Checkbox1");
event.value = Math.abs(a.value)*(b.value);
I don't think it should be super hard, but I can't seem to figure it out 😞 help
Copy link to clipboard
Copied
Although script is not correct (it will give you NaN) but if text field has value and checkbox is checked it should still calculate.
Are you sure your field names are correct? Because in script you use "Text1" and "Checkbox1" but in your second post you refer to "textbox1" and "checkbox1", check console for error.
To get rid of NaN error check that checkbox is checked before you use calculation script.
EDIT:
Try this script as custom calculation script of 'textbox2' field and make sure field names are correct:
var a = Number(this.getField("Text1").valueAsString);
var b = this.getField("Checkbox1");
if(b.valueAsString != "Off")
event.value = Math.abs(a)*Number(b.valueAsString);
else
event.value = "";
Copy link to clipboard
Copied
Did you set number as checkbox export value?
First check that checkbox is checked and then do calculation.
Copy link to clipboard
Copied
Yes. I have set a number (price) in the 'checkbox1' export value. But now I'm thinking maybe this formula should be attached to "checkbox1" instead of "textbox2" which is the place where I want to show the result? I tried it but it's not working, probably because I am missing the formula to display the result of this multiplication in "textbox2"?
I'm sorry for confusing things. I have a checkbox1 with a value that I want (when checked) to multiply by the value from textbox1 (default is set to 1) and show the result in textbox2.
Copy link to clipboard
Copied
Although script is not correct (it will give you NaN) but if text field has value and checkbox is checked it should still calculate.
Are you sure your field names are correct? Because in script you use "Text1" and "Checkbox1" but in your second post you refer to "textbox1" and "checkbox1", check console for error.
To get rid of NaN error check that checkbox is checked before you use calculation script.
EDIT:
Try this script as custom calculation script of 'textbox2' field and make sure field names are correct:
var a = Number(this.getField("Text1").valueAsString);
var b = this.getField("Checkbox1");
if(b.valueAsString != "Off")
event.value = Math.abs(a)*Number(b.valueAsString);
else
event.value = "";
Copy link to clipboard
Copied
Thanks for such quick answer. I will check it tomorrow (bearing in mind checking correct box names) and let you know about result!
Copy link to clipboard
Copied
IT WORKED! Thank you so much! I owe you a coffee 😉
Copy link to clipboard
Copied
Dear Nesa,
Solving this problem created another. I made a few actions like in the topic - checkbox1 value * textbox1 value = results shown in textbox2 - which of course work correctly and show the correct result of the multiplication in textbox2/4/6/8. I have a challenge with summing these values. I selected in the textbox which is supposed to show the total amount [SUM] in the 'Calculation' tab of all textboxes with results (textbox2/4/6/8).. but it shows me wrong results (highly inflated).
Copy link to clipboard
Copied
Check that field calculation order is correct, select 'Prepare form' tool then click on 'More' then on 'Set field calculation order' and make sure that fields that calculate first are on top of the list.
If that doesn't help, please share your file.