Algebraic relation between HTML inputs and updating both of the inputs when user interacts with one of them

I am trying to create 2 inputs dependant on each other like:

<input type="number" name='field1'>
<input type="number" name='twoTimesField1'>

When user interacts with first input i would like to update the other or vice versa.
What is the proper way of achieving this kind of behaviour?