1

I have a photo upload form that I'm working on that works like this:

  1. You click an "Upload Photo" button. jQuery detects the click and triggers a click event to a hidden "file" field within the form, which brings up a dialog to search through your files.
  2. When the user selects a file, the change event is detected on the hidden file field and triggers a form submission. Here is the code:

    // on photo upload button click:
    $("input[name=PhotoUpload]").click(function() {
        $("input[name=Photo]").click();
    });
    
    // on photo upload:
    $("input[name=Photo]").change(function() {
        $("form[name=MediaUpload]").submit();
    });
    

    and the form:

    <form name="MediaUpload" method="post" action="/postad/media.cfm" target="Media" enctype="multipart/form-data">
        <input type="button" name="PhotoUpload" value="Upload Photo">
        <input type="file" name="Photo" size="30" style="visibility:hidden;">
    </form>
    

This works great in Chrome and FireFox, but am having no luck in any version of IE. Any suggestions?

5
  • I seem to recall that IE won't allow for focus() to be assigned to a hidden element, which would probably preclude the click() event too. Commented Aug 13, 2011 at 22:44
  • What's happening in IE? Any errors? Have you looked in the console? Commented Aug 13, 2011 at 22:44
  • Do you see the file dialog in IE? Commented Aug 13, 2011 at 22:48
  • Yeah, forgot to mention. I tried displaying the hidden form elements also. And, no, there are no errors in the console. Commented Aug 13, 2011 at 22:50
  • The file dialog comes up just fine. It just doesn't submit when I select the file. I tried adding a submit event also that displays an alert box when the file is chosen. The alert box displays, but the form never submits. Commented Aug 13, 2011 at 22:52

1 Answer 1

1

I would suggest trying this a little differently:

// on photo upload button click:
$("input[name=PhotoUpload]").click(function() {
    $("#your_dialog").dialog("open");
});

//Remove the `.change` function.
// add the form submit line below after the dialog code changes the `Photo` field
$("form[name=MediaUpload]").submit();

It's easy to confuse IE with javascript. If it hits something that gives it indigestion, it stops processing the js.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.