tags:

views:

1334

answers:

5

Hey all

Can any one know how to make file upload control in javascript, for example using a texbox and a button :)

Thanks in advance

Kishh


Dupe of http://stackoverflow.com/questions/408735/javascript-file-uploads

A: 

Plain HTML:

<input type="file" />

To programmatically create one using javascript:

var el = document.createElement('input');
el.type = 'file';
document.body.appendChild(el);
nickf
hey ya how to get open file dialouge box in javascript :)Kishh
Kishh
el.click() worked in some browsers at various points in time, but as always with file upload fields, the restrictions for security reasons are variable and generally tightening. At one point IE would open the dialogue but not actually allow the upload. It is not in general worth trying to achieve.
bobince
A: 

If you need it to open a dialog (or if you need the ability to select multiple files) you need to use something like SWFUpload.

Ben Alpert
+1  A: 

If my understanding is correct based on this and your previous topic, you're trying to upload a file PURELY in javascript. If this is the case, please note that this is not possible. You're going to need something on the server side to gain the request. Now, however, if you're looking for something that uploads in an "ajax" fashion, there are workarounds to do this by sending the request through a hidden iframe. I know JQuery has this capability built in.

Evan Fosmark
jQuery does not have it built in. You need to download the 'form' plugin I believe.
J-P
A: 

It is impossible to complete your task using pure javascript and using no fileinput html tags, as it is the only thing that allows you to select/upload files. You can only style it.

The other way, as suggested by soprano, is to use some Flash/Java based uploader.

Max
+2  A: 

Although the author of the question asked about form file input styling, I want to let you know that pure JavaScript, AJAX-style uploads are possible with FireFox 3 and greater.

I wrote an exhaustive tutorial about this new feature on my blog.