JSFiddle - React, Tailwind, and code Playground

HTML

<form method="post" id="form">
  Первое поле<br> <input type="text"><br>
  Второе поле<br> <input type="text"><br><br>

  <input type="submit" value="Отправить" name="submit">
</form>

JavaScript

var formContainer = document.querySelector('#form'),
    button = formContainer.querySelector('input[type="submit"]');

button.addEventListener('click', function(event) {
  var inputs = formContainer.querySelectorAll('input[type="text"]');

  [].forEach.call(inputs, function(input, index) {
    input.value = 'Значение переменной i равно ' + (++index);
  });

  event.preventDefault();
});