Irresistable Posted January 6, 2010 Share Posted January 6, 2010 I have a function, that when it's called it creates a File type input. I want it to create a file type input if there is not one there, so only 1 is aloud on a page at a time. - when onchange, it gets deleted, which means you can add another one. How can I do it? function addFileInput() { var d = document.createElement("div"); var file = document.createElement("input"); file.setAttribute("type", "file"); file.setAttribute("name", "attachment"); file.setAttribute("id", "attachment"); file.setAttribute("onchange", "document.getElementById('attachments').style.display = ''; deleteFileInput();"); d.appendChild(file); document.getElementById("attach").appendChild(d); upload_number++; } Link to comment https://forums.phpfreaks.com/topic/187428-how-to-get-this-to-create-1-and-only-1-input/ Share on other sites More sharing options...
Irresistable Posted January 6, 2010 Author Share Posted January 6, 2010 if(document.getElementById('attachment')) { do whatever } else { add field } Although how do I get it so that if 2 fields exist, Link to comment https://forums.phpfreaks.com/topic/187428-how-to-get-this-to-create-1-and-only-1-input/#findComment-989796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.