Change input fields value using Javascript

The text on the input being displayed is changing but when I'm submitting the form, the value is not being recorded. How can I change the value of an input field so that I can record it?

This is the code sample:

$("#"+fieldA).val(totalValue).change()