Sum of two fields

Hello,
I have a form and I need to sum two fields and show the result in another field

Here you go:

<form id="sumForm" is="dmx-serverconnect-form" method="post">
<input id="valSum1" name="valSum1" type="number" step="any" class="form-control" dmx-bind:value="10">
<input id="valSum2" name="valSum2" type="number" step="any" class="form-control" dmx-bind:value="10">
<input id="valSumTotal" name="valSumTotal" type="number" step="any" class="form-control" dmx-bind:value="valSum1.value.toNumber()+valSum2.value.toNumber()">
</form>

Added step 'any' to allow for decimal points.

2 Likes

Hi Alex,

Here is an example that subtracts one field from the other and adds the total to the third field. Should be the same for addition.

 <input class="form-control form-control-sm" id="inputAddTransactionNet" name="inputAddTransactionNet" aria-describedby="input5_help" required="" dmx-bind:value="(inputAddTransactionGross.value.toNumber() - inputAddTransactionTaxes.value.toNumber()).round(2)" type="number">
2 Likes

I can't do it. I tried using the operatiors in the system and get this:

{{input5.value+input13.value+input307.value+input329.value+input341.value}}

These are the actual fields that I would like to sum. How can I do it? also if I want to change the format to % (percent)

You need to convert the values to numbers. And your syntax is all wrong. Are you using the Dynamic Attribute --- > Value to bind your data to a form field? Or are you just displaying the value on the page?

{{input5.value.toNumber()+input13.value.toNumber()+input307.value.toNumber()+input329.value.toNumber()+input341.value.toNumber()}}

For percent you can use the percentage formatter.

I will cahnge to numbers. In order to bind I just create a paragraph and bind the data in there. How can I use the percentage formatter?
Thanks in advance

Tackle one thing at a time :wink:

For the formatter just select your binding, click on the wand. and depending on if your percentage of value is static or dynamic choose the proper tool.

I not have a server connect. I just create a form where I place the info and I will create a PDF out of it. I just have a input field that I just swich to numbers.

Sorry, I am totally lost what you are trying to achieve. :frowning:

Well, I would like to create a formulary that allow some people to enter information and them export it to PDF. Not will be storage in any place. in that formulary I would like to sum some fields that should be in persentage and the result will be in another place. I did use a paragraph and hit the lighting simbol in order to bind it, then in there I make the sum. Please address me to the correct way to do it.

Do you just need % to be there? Or, you need to do some mathematic ecuation in order to return the percentage?

For the text field you point, you can go to dynamic atributes - value and then write the sum there, and use the formatter wand that brad says

Thanks, No, I just need to sum. The mathematic ecuation is already done in others field. basically the user will enter the percentage manually, then that will be mult by another field that will have the value already and will show the result. Until that point is ok. my problems are first the fiel where the user will enter the pecentage manually, I would like to convert to %; the user will enter form example .65 for 65%. I would like to allow the user to enter just 65 and then the field show 65%. my second problem is that I need to sum these fields that get the percentage value from the user that actually are 4 of these fields, basically I would like to show that the total is 100% in order to lets the user know that all the splits are correct.

Hi Alex,

To calculate a sum of the input fields, the field type will need to be a number type, and this field type can't show % character. Instead, show that the number being input is percentage, show it in the column header such as Regional (%).

Try

<form id="sumForm" is="dmx-serverconnect-form" method="post">
    <div class="input-group mb-3">
        <input type="number" class="form-control text-end" id="input1" name="input1" step="any" placeholder=" Percentage" aria-label="Percentage">
        <span class="input-group-text">%</span>
    </div>
    <div class="input-group mb-3">
        <input type="number" class="form-control text-end" id="input2" name="input2" step="any" placeholder=" Percentage" aria-label="Percentage">
        <span class="input-group-text">%</span>
    </div>
    <div class="input-group mb-3">
        <input type="number" class="form-control text-end" id="input3" name="input3" step="any" placeholder=" Percentage" aria-label="Percentage">
        <span class="input-group-text">%</span>
    </div>
    <div class="input-group mb-3">
        <input type="number" class="form-control text-end" id="input4" name="input4" step="any" placeholder=" Percentage" aria-label="Percentage">
        <span class="input-group-text">%</span>
    </div>
    <hr>
    <div class="input-group mb-3">
        <input type="number" class="form-control text-end" id="totalpercent" name="totalpercent" placeholder="Total Percentage" aria-label="Total Percentage" readonly="true" dmx-bind:value="input1.value.toNumber()+input2.value.toNumber()+input3.value.toNumber()+input4.value.toNumber()">
        <span class="input-group-text">%</span>
    </div>
</form>

1 Like

Thanks to all, Was fixed with this way