views:

110

answers:

6

Normally, a file upload dialog is invoked by clicking the button created by <input type="file"/>. But then, I don't want the text field that comes with it. Is there a way to get rid of the text field? Or is there an alternative way to open the file upload dialog without using <input/>?

+1  A: 

You can use a flash alternative. I have used swfUpload, with great success. Uploadify, is a similar alternative. Both of these have nice feature sets, including progress bars and multiple upload.

Dustin Laine
+1  A: 

You could replace it with a flash-button as dustin stated or you could hide the button by css-placing your own button on top of the input element and open the select file box by a script.

Some examples here: inputfile

Simon Karlsson
+1  A: 

Check out the http://www.uploadify.com/ jQuery plugin.

Parker
+1  A: 

Add file input, and set its position to quite far away.
Add a button. Set buttons onclick to $("#myFile").click(); :D

<input id="myFile" name="file" type="file" style="position:absolute;left:-10000px;top:-10000px;">

<button onclick="$('#myFile').click();">Browse</button>
feridcelik
I'm pretty sure that doesn't work for security reasons.
alex
Did you try? works on Chrome.
feridcelik
It works on Chrome and IE but breaks in Opera and Firefox.
Dave
@eridcelik Yes, I tried it with Firefox a few weeks back.
alex
+1  A: 

You can add your own button and position it under the browse button with CSS.

Then set the file input to have 0 opacity.

alex
+1  A: 

agree with alex

<style>
.file_wrap{
    background:url(file.jpg);
    overflow:hidden;
    width:30px;
    height:10px;
}
.file_wrap input{
    opacity:0;
    font-size:999px;
    cursor:pointer;
}
</style>
<div class="file_wrap">
   <input type="file" />
</div>
diablero13