Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a script that is dived as:

HTML:

<div id="wrapper">
     <div id="container">
        <div id="button">Click me!</div>
        <form>
            <input type="file" />
        </form>
      </div>
     <div id="notice">File is uploaded!</div>
</div>

JavaScript(JQuery 2):

$(document).ready(function () {
    $("input").on("change", function () {
       $("div#notice").fadeIn();
        //$("form").submit(); //If you want it to submit on your site uncomment this
    });
 });

CSS:

div#wrapper {
    background-color: #ccc;
    position: absolute;
    width: 300px;
    height: 200px;
}
div#wrapper > form > input {
    color: rgba(0, 0, 0, 0);
    zoom: 1;
    filter: alpha(opacity=0);
    opacity: 0;
    color: rgba(0, 0, 0, 0);
 }
div#container {
    width: 200px;
    height: 20px;
    overflow: hidden;
}
div#button, input {
    position: absolute;
    top: 0px;
    left: 0px;
    cursor: pointer;
 }
div#button {
    z-index: 1;
    background-color: #AAA;
 }
input {
    z-index: 2;
    background-color: rgba(0, 0, 0, 0);
    opacity: 0;
    alpha: filter(opacity=0);
    font-size: 25px;
    color: rgba(0,0,0,0);
    filter: alpha(opacity=0);
    zoom: 1;
 }
div#notice
{
    background-color: green;
    display: none;
    position: absolute;
    bottom: 0px;
    left: 0px;
 }

Note: This issue was there before blur was put to hide the flashing icon in IE.

In Chrome and Firefox the button only requires a single click. In IE 10 it requires a double click, which I don't want. I am trying to think of a way to make it single click.

The only thing I've tried so far is to .render("click") on the input, but that didn't work.

JSFiddle: http://jsfiddle.net/plowdawg/mk77W/

share|improve this question
 
It probably has something to do with the fact that when you click it, it puts you into the text portion of the file input, so you're clicking on the text-side of the fileinput rather than the browse button. –  Kevin B Jun 19 at 16:04

2 Answers

up vote 1 down vote accepted

While @bastos.sergio is right about it happening in the text section there is a way to get around this if you are comfortable using JavaScript.

You will need:

  • A wrapper div tag
  • An inner dev tag
  • Some sort of form input
  • JQuery (tested on 2.1)

Steps:

  1. Create the "wrapper" div
  2. Create an inner "button " div
  3. Place the form element underneath the inner "button" div
  4. Set the "wrapper" and "inner" divs to the same size
  5. Set overflow:hidden on the wrapper
  6. Create a JQuery script for the "inner" div setting the on click function
  7. In the "inner" function click function call .click() on the input

Seems to work for me in IE 10.

Example code: JsFiddle.

share|improve this answer

The double click is happening on the text portion of the file upload, like @TravisPessetto stated.

Since it's not possible to hide/remove the text portion out of the file input control, I recommend that you put a regular button over the file input.

See here for more details.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.