JSFiddle - React, Tailwind, and code Playground

by f0t0n

HTML

<form action="" id="my-form">
    <input type="text" id="inp" />
</form>

JavaScript

var btn,
    input,
    form;
input = document.getElementById('inp');
form = document.getElementById('my-form');
for(var i = 0; i < 5; i++) {
    btn = document.createElement('input');
    btn.type = 'button';
    btn.value = 'Append ' + i;
    form.appendChild(btn);
    btn.onclick = (function(theNumberToAppend) {
        return function() {
            input.value += theNumberToAppend;
        };
    })(i);
}