1

I have a page where there is an input file. In this page there also is an iframe that contains another input file.

So, when the input file in main page changes, I want that the input file inside iframe also changes its value to the value of external input file.

But it doesn't work, i use this code in main page:

$('#iframe').contents().find('#input_file').val(myvalue);

The value of #input_file file remains empty. What could be the problem

Charles Sprayberry
  • 7,741
  • 3
  • 41
  • 50
Giovanni Bitliner
  • 2,032
  • 5
  • 31
  • 50

1 Answers1

4

You cannot change the value of a file input (for security reasons).

See: Dynamically set value of a file input

Community
  • 1
  • 1
aepheus
  • 7,827
  • 7
  • 36
  • 51
  • It was possible to change in older versions of browsers, but as aepheus says, now its not possible for security reasons. I'm telling this because you could find an old post with some workaround, but it will not work in any modern browser. – Alex Angelico Aug 03 '11 at 17:13
  • So, i resolved my problem not setting a specific value of input file but adding an input file with specific value. – Giovanni Bitliner Aug 03 '11 at 17:31
  • I'm continuining to have problems. Is there some workaround? I need it to create an upload file module, through an iframe. In django. – Giovanni Bitliner Aug 03 '11 at 20:28
  • Precisely now i'm using `target` attribute of form tag, but this attribute is deprecated. Is there alternatives? – Giovanni Bitliner Aug 03 '11 at 21:22
  • With target attribute i have resolver. Even if target attribute is deprecated, it works fine and it is also used by good enterprises like facebook, so by that time i usually use this solution. – Giovanni Bitliner Feb 02 '12 at 12:31