views:

38

answers:

2

I have a windows, which in there is a upload button. When user click this button, it will popup a page for user to upload the desired file. But i dont know how can the main page detect if the user uploaded and add a field to the main form?

I've been seeing this somewhere but i dont remember so i can't go back to check out the source JS..

If anyone know, please give me an advice.

Thanks in advance :)

PS: im working on Jquery

A: 

From your popup window you can access the parent window through window.opener.

$("#upload-button").click(function(evt){
  window.opener.trigger();
});

would call a function trigger() in the parent window each time the upload button has been clicked.

moxn
+1  A: 

A variation of what moxn said,

The popped up window accepts the file upload, it sends the file to the server and then returns another page indicating whether the file was uploaded successfully.

I don't know what server side language you are using but, on that return page you should have something like:

if (file was uploaded successfully){
 print "<html>
  <body onload='window.opener.trigger()'>
     file uploaded successfully, please close this window
  </body>
 </html>";
}else{
 print "<html>
  <body>
     could not upload file due to [reason], please re-upload the file
  </body>
 </html>";
}

Notice the body onload='' on the first part of the conditional...

Hope that helps

pǝlɐɥʞ