Skip to main content
Participant
April 4, 2023
Answered

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

  • April 4, 2023
  • 1 reply
  • 1200 views

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

This topic has been closed for replies.
Correct answer Nesa Nurani

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

1 reply

Nesa Nurani
Community Expert
Community Expert
April 4, 2023

Did you set number as checkbox export value?

First check that checkbox is checked and then do calculation.

xWilczyAuthor
Participant
April 4, 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.

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
April 4, 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 = "";