Monthly Archives: January 2008

Send a post request to a popup

Today i want to send the post request from a form to a pop up window and the solution is pretty simple first we have to create our form and then we add a target attribute where we specify the name that our popup window will have second we add a onsumbit call to the form that will popup the new window and submit the form we also have to assign and id to our form that will be usefull when calling the function that popup the windows

  2. <form action="index.php" method="post" target="windowName" onsubmit="return postPopup();" id="postForm">
  3.  <input type="text" name="value1" />
  4.  <input type="text" name="value2" />
  5.  <!– put all the form elements here –>
  6.  <input type="submit" />
  7. </form>

  2. <script type="text/javascript">
  3. function postPopup( formElem ) {
  4.         // here we popup the new window, the second attribute have to be the same as the form target attribute
  5. , ‘windowName’, ‘width=800, height=400, resizable=yes, scrollbars=yes, toolbar=no, location=no, directories=no, status=no, menubar=no’ );
  6.         // we submit the form 50 milliseconds after so the browser creates the popup
  7.         setTimeout("document.getElementById(‘postForm’).submit();",50);
  8.         // we stop the regurar form submit
  9.         return false;
  10. }
  11. </script>