Jump to content

How to get this to create 1 and only 1 input


Irresistable

Recommended Posts

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++;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.