Jump to content

customizing File upload input


Irresistable

Recommended Posts

I believe you cannot do this, as it is entirely browser based, and the browsers do not let you customize the file upload form.

 

The only possible thing I can think that you could *maybe* do, is to hide the file input altogether, create a dummy file input, then use javascript to take whatever data the user enters and put it in the file upload input using javascript. But I suspect this will not work, as file upload inputs are resistant to javascript for security reasons.

It's all javascript, it doesn't make much sense to me. However, I had a go at creating something similar.

http://developers-community.com/test.php <-- Thats what I've got so far.

Click on "Attach" brings up a input, browse a file. Then the input disappears and a div gets displayed.

Click on "Attach" and a blank new one gets displayed.

The next thing I need to do is make it so that when onchange, it passes the file name. eg: filename.jpg over to the div in a seperate div, and they go underneath each other.

Any ideas?

Here is my code so far.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var upload_number = 5;
function deleteFileInput() {
	var att = document.getElementById("attach");
	att.removeChild(att.childNodes[0]);
}
function addFileInput() {
	var d = document.createElement("div");
	var file = document.createElement("input");
	file.setAttribute("type", "file");
	file.setAttribute("name", "attachment"+upload_number);
file.setAttribute("id", "attachment");
file.setAttribute("onchange", "document.getElementById('attachments').style.display = ''; deleteFileInput();");
	d.appendChild(file);
	document.getElementById("attach").appendChild(d);
	upload_number++;
}
</script>
</head>

<body>
<a href="javascript:addFileInput();">Attach</a>
<div id="attachments" style="width:150px; height:180px; border:1px solid #000; display:none;"> </div>
<div id="attach"></div>
</body>
</html>

 

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.