Created
July 19, 2011 13:54
-
-
Save andreaseger/1092429 to your computer and use it in GitHub Desktop.
dynamically add and remove dom elements(with js)
This file contains hidden or 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
<div class="bodyClip" > | |
<div id="moreUploads"> | |
<div id="att1"> | |
<input type="file" name="appdocs_services[attachment1]" id="appdocs_services[attachment1]" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" /> | |
</div> | |
</div> | |
<div id="moreUploadsLink" style="display:none;"><a href="javascript:addFileInput();">Eine weitere Datei hinzufügen.</a></div> | |
<p><i>(Format erlaubt : PDF, doc)</i></p> | |
</div> |
This file contains hidden or 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 upload_number = 2; | |
function addFileInput() { | |
var d = document.createElement("div"); | |
d.setAttribute("id","att"+upload_number); | |
var file = document.createElement("input"); | |
file.setAttribute("type", "file"); | |
file.setAttribute("name", "appdocs_services[attachment"+upload_number+"]"); | |
var link = document.createElement("a"); | |
link.setAttribute("href","javascript:removeFileInput(" + upload_number + ");"); | |
var linkText = document.createTextNode("entfernen"); | |
link.appendChild(linkText); | |
d.appendChild(file); | |
d.appendChild(link); | |
document.getElementById("moreUploads").appendChild(d); | |
upload_number++; | |
}; | |
function removeFileInput(i) { | |
var div = "att"+i; | |
var d = document.getElementById("moreUploads"); | |
var olddiv = document.getElementById(div); | |
d.removeChild(olddiv); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dssdsdsd