Only field values get posted on form submission. JavaScript changes to HTML are not included because they are client-side changes; this is standard for web forms and is important at least for security since client browsers can do whatever they want to the page content.
If you want the HTML changes to be "saved" you have a couple options:
Modify Your JavaScript
Update your JavaScript to run as soon as the form loads so it will re-add those fields when it is opened in the history view or saved to the repository.
However, note that aside from checkboxes and radio buttons, all field types are converted to div elements so the code for retrieving/populating those values has to be dynamic.
JavaScript still executes when the document is saved to the repository, you just have to make sure it is configured properly to account for the formatting differences.
Leverage Dataset Variables
You could add the data set variables for those fields to your HTML. If they are blank, like with the starting form, the value would just be blank (and your JS could fill them in).
However, as long as your hidden fields are saved with the submission, then they should be available for the HTML for subsequent tasks/processes to prefill.
Note that data set variables only reference saved values (i.e., they don't update in real-time like calculations), so you'll still need the JavaScript on the initial form.