Created
June 15, 2017 03:05
-
-
Save aug2uag/8e4f8ae11f59f1e3630745dd4255c616 to your computer and use it in GitHub Desktop.
action form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var iiii = 0; | |
function increment() { | |
iiii += 1; | |
} | |
function createActionsInit() { | |
function removeElement(parentDiv, childDiv){ | |
if (childDiv == parentDiv) return | |
if (document.getElementById(childDiv)) { | |
var child = document.getElementById(childDiv); | |
var parent = document.getElementById(parentDiv); | |
parent.removeChild(child); | |
} | |
} | |
$('#textareaFunction').on('click', function(e) { | |
e.preventDefault(); | |
var yattrs = [{"cols": "17"},{"placeholder": "message.."},{"Name": "textelement_" + iiii}]; | |
var gattrs = [{"src": "delete.png"},{"onclick": "removeElement('myForm','id_" + iiii + "')"}]; | |
actionFormEl('TEXTAREA', yattrs, gattrs, 'myForm', iiii); | |
}); | |
$('#emailFunction').on('click', function(e) { | |
e.preventDefault(); | |
var yattrs = [{"type": "text"},{"placeholder": "Email"},{"Name": "textelement_" + iiii}]; | |
var gattrs = [{"src": "delete.png"},{"onclick": "removeElement('myForm','id_" + iiii + "')"}]; | |
actionFormEl('INPUT', yattrs, gattrs, 'myForm', iiii); | |
}); | |
$('#nameFunction').on('click', function(e) { | |
e.preventDefault(); | |
var yattrs = [{"type": "text"},{"placeholder": "Name"}, {"Name": "textelement_" + iiii}]; | |
var gattrs = [{"src": "delete.png"},{"onclick": "removeElement('myForm','id_" + iiii + "')"}]; | |
actionFormEl('INPUT', yattrs, gattrs, 'myForm', iiii); | |
}); | |
$('.resetElements').on('click', function(e) { | |
document.getElementById('myForm').innerHTML = ''; | |
}); | |
$('#act_actionform').on('click', function(e) { | |
// submit action | |
}); | |
} | |
function actionFormEl(_i, yattrs, gattrs, id, idx) { | |
var r = document.createElement('span'); | |
var y = document.createElement(_i); | |
var g = document.createElement("IMG"); | |
function applyAttrs(input, el) { | |
input.forEach(function(_attr) { | |
for (var key in _attr) el.setAttribute(key, _attr[key]); | |
}); | |
} | |
applyAttrs(yattrs, y); | |
applyAttrs(gattrs, g); | |
r.appendChild(y); | |
r.appendChild(g); | |
r.setAttribute("id", "id_" + idx); | |
increment(); | |
document.getElementById(id).appendChild(r); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment