1

I'm trying to dynamically create an iframe with a <form> and form child <input> element in it using jQuery. For some reason, the load event of the iframe is never firing, so I can't add the <input>. What am I missing?

Very short: http://jsfiddle.net/LLKej/10/

EDIT: I'm trying to detect when the iframe loads

JQueeeer
  • 1,321
  • 2
  • 9
  • 5

3 Answers3

0

read the console. there is no load event for forms.

Naftali
  • 144,921
  • 39
  • 244
  • 303
0

Unfortunately there is no onload or load event for an HTML form. The only available actions besides the typical events like click, focus, and change, are submit and reset.

References: https://developer.mozilla.org/en/DOM/HTMLFormElement#Methods

alvincrespo
  • 9,224
  • 13
  • 46
  • 60
0

The load event is firing (confirm by placing an alert inside of your load event). However, you are not appending content to the iframe properly:

$iframe.load(function() {

    var $uploadForm =  $("<form target='" + iframeName + "' action='" + options.postUrl + "' method='post' enctype='multipart/form-data' />");

    $iframe.contents().find("body").append($uploadForm);
    $uploadForm.append($("<input type='file' value='" + options.file + "' />"));

    if (options.selectFile === true) {
         $uploadForm.find("input").click();   
    } 
});

Note the call to .contents() before the append call.

Additionally, I don't believe it's possible to programmatically launch a file input's browse functionality (confirmed by this question).

Community
  • 1
  • 1
Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307