Yes it is possible. For instance:
<form id="sampleForm"> <input type="text" id="fromInput" /> <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>
with javascript
function fillValues() { var value = $("#fromInput").val(); var fields= $(".autofiller"); fields.each(function (i) { $(this).val(value); }); } $("#filler").click(fillValues);
Suppose you have jQuery . You can see how it works here: http://jsfiddle.net/ramsesoriginal/yYRkM/
Although I would like to point out that you should not include jQuery only for this function ... if you already have this, this is great, but just go to:
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 ; }
You can also see this in action: http://jsfiddle.net/ramsesoriginal/yYRkM/
source share