setAttribute doesn't persist upon filling out the next form field
I have an html form where some of the calculations are done by the setAttribute function. But whenever I fill out the next field, the calculated amounts do not persist. For example:
First field is total amount - e..g $100
Then next field is bunch of radio buttons - e.g. 10%, 25%, 50%, 75%, 100%. The default is 50%
There are two readonly fields (amount_one and amount_two) that are populated by setAttribute based on whichever radio button is selected in step 2. For example, with default 50% - amount_one is $50 and amount_two is $50. But if I select 25%, then amount_one is $75 and amount_two is $25
The code for step 1 - 3 works fine.
Below the Step 3, I have a note field that is of type textarea. Whenever I type something in this field, the value of amount_one and amount_two in step 3, goes back to to default i.e. $50 each. The radio button selected in step 2 stays at 25%.
How do I make step 3 values persist to calculated amount?
Below is the partial javascript code used for Steps 1 -3.
var radval = 0.25; // Value selected by the radio buttion
var amount = document.getElementById("total_amount");
responsible = radval * amount.value;
yourshare = amount.value - responsible;
let resp = responsible.toFixed(2);
let ysha = yourshare.toFixed(2);
document.getElementsByName("amount_two")[0].setAttribute('value', resp);
document.getElementsByName("amount_one")[0].setAttribute('value', ysha);
@vincent15000 There is no other js code. Basically, any other field I edit, the two calculated fields go back to default. The only time these two values should change should be when i change the original amount or the split percentage. I am including both the HTML and JS code.
Below are the list of fields after the radio button.