JSFiddle - React, Tailwind, and code Playground
formgen.js
by Jennifer Perrin
HTML
<div id="myform"></div>
JavaScript
Form = function (a, m, e, txt) {
var t, l;
this.F = document.createElement("form");
this.F.action = a;
this.F.method = m;
if (e != '') this.F.enctype = e;
this.fld = document.createElement("fieldset");
t = document.createTextNode(txt);
l = document.createElement("legend");
l.appendChild(t);
this.fld.appendChild(l);
}
Form.prototype.addInput = function (tx, l, n, v, st) {
var d, t, lab, inp;
switch (tx) {
case 'text':
case 'radio':
case 'checkbox':
case 'submit':
case 'button':
d = document.createElement("div");
t = document.createTextNode(l + ' ');
lab = document.createElement("label");
lab.appendChild(t); /*@cc_on @if(@_jscript) @if(@_jscript_version<9) inp=document.createElement("<input name='"+n+"'>");@else inp=document.createElement("input");inp.name=n; @end @else */
inp = document.createElement("input");
inp.name = n; /* @end @*/
inp.type = tx;
if (tx == 'radio') {
if (this.n != +this.n) this.n = 0;
this.n++;
n += this.n;
}
inp.id = n;
lab.htmlFor = n;
inp.value = v;
if (st.match(/c/i)) inp.checked = true;
if (st.match(/d/i)) inp.disabled = true;
if (st.match(/r/i)) inp.readOnly = true;
if (tx == 'radio' || tx == 'checkbox') {
d.appendChild(inp);
d.appendChild(lab);
} else {
d.appendChild(lab);
d.appendChild(inp);
}
this.fld.appendChild(d);
break;
default:
}
};
Form.prototype.addTextarea = function (l, n, w, h, v, st) {
var d, t, lab, inp, c;
d = document.createElement("div");
t = document.createTextNode(l + ' ');
lab = document.createElement("label");
lab.appendChild(t); /*@cc_on @if(@_jscript)...