Hello, I would need to upload two files from two different iframes, but they have to be treated at the same time by the same server script, so I'd need to send them with a unique submit.

Is this possible?

For what I have seen, the submit targets a single iframe so I can't imagine a way to do this.

Searching in google couldn't find anything related, lots of unrelated results.

Dani AI

Generated

Good to see the thread is marked solved by . For others who hit the same question years later, a few practical options and pitfalls to keep in mind.

Modern, convenient route (same-origin): read the File objects from each file input and send them together in one multipart POST using FormData + fetch or XHR2. The parent page can access inputs inside child iframes only when those frames are same-origin. The browser will build the correct multipart body for you, so do not set Content-Type manually. Example pattern:

// parent page (frames must be same-origin)
var fileA = document.getElementById('frameA').contentWindow.document.getElementById('fileA').files[0];
var fileB = document.getElementById('frameB').contentWindow.document.getElementById('fileB').files[0];

var fd = new FormData();
fd.append('fileA', fileA);
fd.append('fileB', fileB);

fetch('/upload', { method: 'POST', body: fd });

Fallbacks and cross-origin cases: if frames are cross-origin or you must support old browsers that lack FormData/.files, use a server-side aggregation strategy. Give both forms the same upload token/ID (hidden field) and have each iframe submit separately; the server stores each part and treats them together once both arrive. Alternatively, use postMessage to coordinate uploads from each frame so each frame posts directly with the shared token. Watch same-origin restrictions and CORS when using fetch/XHR.

References: FormData, Using Fetch, postMessage.

Sorry this wasn't a problem using FIELDSET and 1 iframe. Solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.