views:

20

answers:

2
<input type="file" />

Can I replace the file input field (above) with a simple button:

<button type="submit">Upload</button>

File input doesn't fit nicely into the design, and styling it is a pain so if its possible to use a button instead for file uploading, thats also cross-browser compatible, that'd be awesome!

Thanks!

A: 

You can style with CSS and DOM the input type file

See this page

Pentium10
No, I really don't want to spend any time styling it. I'm looking for a workaround to use a single button instead, possible?
Nimbuz
As far I know you can do that by using CSS only. AFAIK you cannot replace with a button, especially when you need the browser to show a file picker dialog for you.
Pentium10
+1  A: 

1- You can't call the open dialog using a button, you can just show the dialog using the input file field, or using a flash component.

2- You can work around this by putting input file on a button "using CSS" and set this input file transparent so it will look like the user is clicking on the button but infact he is clicking on the transparent input file.

Sample: http://www.quirksmode.org/dom/inputfile.html

Amr ElGarhy
#2 will be perfect, how do I do that? I'm using jQuery. Thanks!
Nimbuz
you can do that using CSS, will set the position of the button absolute and play with the z-index, and input file opacity. i will try to find a sample for you to do that.
Amr ElGarhy
i put a sample in my answer
Amr ElGarhy
Ah, wish that was in jQuery, but thanks!
Nimbuz
i think this issue has nothing to do with jquery as its a pure css design issue.
Amr ElGarhy