1 Replies - 2887 Views - Last Post: 20 October 2012 - 05:47 PM

#1 drayarms  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 199
  • Joined: 18-May 11

Having trouble passing data from iframe to parent

Posted 24 September 2012 - 05:23 PM

Hello folks, the problem is very straight forward. I have a form which uploads pictures. The form is located in a modal dialog box, so the php script that handles the form is processed within an iframe in the same dialog box as the form. The success or error messages from the script are then echoed out within the iframe. Everything works good so far, but the issue is, I want to transfer those feedback messages from the iframe back into the parent dialog box, specifically into another div within the dialog box which I call upload_pic_feedback. Here is the code I have which wouldn't work. Any ideas why I got it wrong?
PS I need to transfer the data from iframe to feedback box because at the end of the day, I plan to render the iframe invisible to the user. I also want to hide the form and display the feedback div which by default is hidden when upload has successfully taken place

Main HTML containing the dialog box

<div id = "dialog_box">

    <form id = "upload_pic_form"  enctype="multipart/form-data" action="picture_upload.php" target = "pic_upload_iframe"   method="post">
           <input name="MAX_FILE_SIZE" value="10000000" type="hidden">

           <input name="picture" accept="image/jpg, image/png, image/jpeg, image/bmp, image/gif, video/*" type="file"> 

	   <button class = "button" name="submit" type="submit"> Submit! </button>

     <iframe  id = "upload_pic_iframe" name="pic_upload_iframe"   width = "100px" height = "100px">


     <div id = "upload_pic_feedback" style = "display:none">
                //The picture_upload.php script which handles the form, runs within this iframe. It generates either a 
                //success or error variable which is echoed below

		if(isset($error)){echo $error;}

		if(isset($success)){echo $success;}

                //And finally here is the script which is supposed to hide the form, show the feedback div and transfer 
                //the variables from iframe to feedback div


		<script type = 'text/javascript'>

			$('#upload_pic_form', top.document).hide();//Hide the form in the parent dialog box

			$('#upload_pic_feedback', top.document).show();//Show the feedback div

                        var send_to_parent = $('#upload_pic_iframe', top.document).html();

			$('#upload_pic_feedback', top.document).append(send_to_parent);//Append the data



     </div> <!--closes upload pic feedback-->


PS I've also tried parent.document in place of top.document, all in vain.

Is This A Good Question/Topic? 0
  • +

Replies To: Having trouble passing data from iframe to parent

#2 BobRodes  Icon User is offline

  • Lovable Curmudgeon
  • member icon

Reputation: 594
  • View blog
  • Posts: 3,055
  • Joined: 19-May 09

Re: Having trouble passing data from iframe to parent

Posted 20 October 2012 - 05:47 PM

I ran into a problem with iframes a while ago too. You haven't said what kind of problem you're having ("doesn't work" should be forbidden on this site) but this link might have some information that helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1