Say you have a page, and you want to submit a form without disturbing the page. You can do this by making the target a hidden IFRAME. The code in the IFRAME can then call back to its parent if you need confirmation.

But say also you want multiple forms to be submitted at once. In that case, you can generate multiple IFRAMEs dynamically, and submit forms to each one.

Note the Internet Explorer problem/workaround shown commented below. Thanks a million to Raul for his posting!

(Javascript code in the main page)

function do_dynamic_form()
{
   // global counter to make each submission unique
   g_rotate_counter++;  

   // make a new IFRAME.  Give it a unique name and ID.  The ID is needed for the IE bug
   el = document.createElement("IFRAME");
   f_name = "rotate_iframe" + g_rotate_counter;
   el.name = f_name;
   el.id = f_name;

   // find a place to insert the IFRAME.  Probably could just append to the end of the doc also
   el2 = document.getElementById("iframe_area");
   el2.appendChild(el);

   // For some reason IE doesn't repond to frame.name = some_name;
   if(self.frames[f_name].name != f_name)
   { /* *** IMPORTANT: This is a BUG FIX for Internet Explorer *** */ 
      self.frames[f_name].name = f_name;
   }

   // set the target, set the script to run and submit!
   document.myform.target = el.name;
   document.myform.action = "rotate.php?dir=" + rotate_right + "&id=" + id;
   document.myform.submit();
}

(code on the script called)

<?php
if (isset($_GET['id']))
{   echo "ready to rotate id!".$_GET['id'];
}
else
{   echo "not ready to rotate!";
}
?>
<SCRIPT type="text/javascript">

// call back the parent
parent.post_rotate(1, <? echo $size .", \"". $target_path."\",". $photo_id?> ); 

</SCRIPT>

-- MattWalsh - 07 Mar 2007

Topic revision: r1 - 07 Mar 2007 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback