Dividing a number, then display result in form field

The form I’d like to modify populates this field (balance amount) upon the page appearing:

<div class="col-md-10">
<input type="text" readonly="true" class="form-control input-md" type="number" placeholder="00" value="{{balance}}">  
</div>

I’d like to divide that balance amount by 2, and have that result display it’s own seperate form field.
Any help with this is appreciated.

The following will work:

<input id="source-field" type"number">
<input id="target-field" type="number" readonly="true">

<script>
const sourceField = document.querySelector('#source-field');

sourceField.addEventListener('keyup', (event) => {
  const userNumber = event.target.value;
  const changeField = document.querySelector('#target-field');

  changeField.value = userNumber / 2;
});
</script>

When you change the source field, the target field will update.

2 Likes
Sponsor our Newsletter | Privacy Policy | Terms of Service