Sum of two fields

Hi all,

How do I take two numeric fields and have the sum be placed in a third field. As the two numbers update, I want to the third box to update in real time. Is that possible?

Hi Andre,

Yes, it’s possible. You can add an onchange custom attribute for the two textboxes for which you want the sum, and in the attribute value you can add some JavaScript code, such as:

document.getElementById("REQUEST_TEXTBOX3").value = parseInt(document.getElementById("REQUEST_TEXTBOX1").value) + parseInt(document.getElementById("REQUEST_TEXTBOX2").value);

Hi All,
Can I add If statement with my JavaScript code in the attribute value?, such as:
document.getElementById(“REQUEST_TEXTBOX3”).value = parseInt(document.getElementById(“REQUEST_TEXTBOX1”).value) + parseInt(document.getElementById(“REQUEST_TEXTBOX2”).value);
document.getElementById(“REQUEST_TEXTBOX3”).value = parseInt(document.getElementById(“REQUEST_TEXTBOX2”).value);

Hi Pnicoll,

So I’ve been using this formula you gave but I have a few problems:

  1. There is also a file upload area on the form which refreshes the page once uploaded. This brings the sum total field back to “0”. The only way to rerun the formula (or equation) is to go back to those fields and change them again but that’s not practical for the end user.
  2. If you don’t add any files, those sum fields (seemingly randomly) go to “0” after navigating through the workflow.
  3. When I start with the first field in the calculation, the sum field goes to NaN until I updated the second field in the calculation. It’s fine with me but I’d prefer it be blank until I change both fields.

I feel like the best way to do this calculation is to use JQuery or .NET in the code behind. What do you think?

Hi Rami,

No, JavaScript accepts only JavaScript language.
You can use JQuery which is the easiest way to retrieve values from fields:

if($(’#REQUEST_DROPDOWNLISTBOX’).val() == “Value of Item 1”){…}

Best Regards,

Hi Andre,

A File Upload field does need to do a postback in order to upload a file. You need to handle postbacks in order to avoid this issue. I would go with using .NET code behind to handle this. Kindly open a ticket in our Helpdesk system if you need further assistance.

Best Regards,

I’m not sure how an IF statement would work here. I just need to add two fields. I need two fields that are Strings to be converted to Integers, added together and inserted into another field. Does that make sense?

Hi Andre,

That reply was for r.tobasi’s question.

Hi @pnicoll

Thanks for your answer, it worked for me for a textbox.

However I try to set it up for a Gridview but I cannot find the good way to make it works.
In my case I try to multiply two datas from the same row into the last column of that same row.

Do you have an idea on how to set it up ?

Thanks in advance,