JSFiddle - React, Tailwind, and code Playground

by ramsesoriginal

HTML

<form id="sampleForm">
    <input type="text" id="fromInput" placeholder="Fill me" />
    <input type="text" class="autofiller"/>
    <input type="text" class="autofiller"/>
    <input type="text" class="autofiller"/>
    <input type="button"value="Fill" id="filler" >
    <input type="button"value="Fill without jQuery" id="filler2" onClick="fillValuesNoJQuery()">
</form>

JavaScript

function fillValues() {
      var value = $("#fromInput").val();
      var fields= $(".autofiller");
      fields.each(function (i) {
        $(this).val(value);
      });
}

fillValuesNoJQuery = function () {
      var value = document.getElementById("fromInput").value;
      var oForm = document.getElementById("sampleForm");
      var i = 0;
      while (el = oForm.elements[i++]) if (el.className == 'autofiller') el.value= value ;
}

$("#filler").click(fillValues);