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++; } Quote Link to comment 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, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.