views:

815

answers:

3

Hi there!

How do use this image:

http://h899310.devhost.se/proxy/newProxy/uplfile.png

Instead of the regular:

<input type="file" />
+2  A: 

Have a look at Styling an input type="file".

cletus
+1  A: 

I'm not very sure on whether you want to style file upload fields, or whether you simply want to use a png file in a style.

Quirksmode.org has a section on styling file upload fields though, that you would want to refer to.

If you want to use the PNG file to use in a style inside a page, you should like at how to set backgrounds using images, although this may not work for all HTML elements.

Vineet Reynolds
A: 

I did something like this and it worked perfectly!

<script type="text/javascript">

var t = 0;
var IE = navigator.appName;
var OP = navigator.userAgent.indexOf('Opera');
var tmp = '';

function operaFix() {

   if (OP != -1) {
      document.getElementById('browser').style.left = -120 + 'px';
   }

}


function startBrowse() {

   tmp = document.getElementById('dummy_path').value;
   getFile();

}

function getFile() {

   // IF Netscape or Opera is used...
   //////////////////////////////////////////////////////////////////////////////////////////////
   if (OP != -1) {

   displayPath();

      if (tmp != document.getElementById('dummy_path').value && document.getElementById('dummy_path').value 

!= '') {

         clearTimeout(0);
         return;

      }

   setTimeout("getFile()", 20);

   // If IE is used...
   //////////////////////////////////////////////////////////////////////////////////////////////
   } else if (IE == "Microsoft Internet Explorer") {

      if (t == 3) {

         displayPath();

         clearTimeout(0);
         t = 0;
         return;

      }

   t++;
   setTimeout("getFile()", 20);


   // Or if some other, better browser is used... like Firefox for example :)
   //////////////////////////////////////////////////////////////////////////////////////////////
   } else {

      displayPath();

   }

}


function displayPath() {

   document.getElementById('dummy_path').value = document.getElementById('browser').value;

}

</script>



<style type="text/css">

#browser
   {
   position: absolute;
   left: -132px;
   opacity: 0;
   filter: alpha(opacity=0);
   }

#browser_box
   {
   width: 104px;
   height: 22px;
   position: relative;
   overflow: hidden;
   background: url(button1_off.jpg) no-repeat;
   }

#browser_box:active
   {
   background: url(button1_on.jpg) no-repeat;
   }

#dummy_path
   {
   width: 350px;
   font-family: verdana;
   font-size: 10px;
   font-style: italic;
   color: #3a3c48;
   border: 1px solid #3a3c48;
   padding-left: 2px;
   background: #dcdce0;
   }

</style>

<body onload="operaFix()">


   <div id="browser_box">
   <input type="file" name="my_file" id="browser" onclick="startBrowse()" />
   </div>

</body>