Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How can I multiply 'checkbox1' value with 'textbox1' value and get the result of it in 'textbox2'

New Here ,
Apr 04, 2023 Apr 04, 2023

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

TOPICS
JavaScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Apr 04, 2023 Apr 04, 2023

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 = "";

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 04, 2023 Apr 04, 2023

Did you set number as checkbox export value?

First check that checkbox is checked and then do calculation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 04, 2023 Apr 04, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 04, 2023 Apr 04, 2023

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 = "";
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 04, 2023 Apr 04, 2023

Thanks for such quick answer. I will check it tomorrow (bearing in mind checking correct box names) and let you know about result!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 05, 2023 Apr 05, 2023

IT WORKED! Thank you so much! I owe you a coffee 😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 06, 2023 Apr 06, 2023

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2023 Apr 06, 2023
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines