0

Hi i have a requirement like follows i have a file element in one form this form contains many other fields also so i cannot submit it but after the file has chosen i need to upload that so i created the second form with iframe. I am not able to copy the file element from one form to another especially in ie i tried with cloneNode and appendChild both are not working any suggestions. i am really stuck.

<form name ="form1">
   <input type="file"/>
</form>

<form name="form2">       
<form> 

1 Answers1

1

Looks like cloneNode has allowed to clone file inputs. Possible code may be as follows:

<form name="form1">
  <input id="file1" type="file" onchange="copy_file_input()" />
</form>
<form name="form2" enctype="multipart/form-data">
  <input type="hidden" name="test" value="form2sent" />
</form>
function copy_file_input() {
  var target_form = document.forms.form2;
  if (target_form.file2 != undefined) {
    target_form.removeChild(target_form.file2);
  }
  var elem = document.getElementById('file1');
  var copy = elem.cloneNode(true);
  copy.name = 'file2';
  target_form.appendChild(copy);
}

Also this link may be useful.

Community
  • 1
  • 1
Stano
  • 8,749
  • 6
  • 30
  • 44