...

View Full Version : window open method=post



alan_b56
06-14-2010, 04:57 PM
Situation: adding code to an HTML page that I can add to, but not change any existing code, as it is from a vendor and gets generated on the fly. I need to add a button within the existing <form></form> construct that already has a submit button and the form has an "action=" in it.

What I have done is added <input type=button onClick=myscript().... Myscript() opens a .php file as a popup, positions it correctly, and all that. What it doesn't do is move the values to the .php like a method=POST would. Is there anyway to to do this, or do I have to do a set of document.write statements?

Existing code:


<!-- vendor's untouchable code -->
<form method=post name="MainForm" action="xxx.asp?yyy" onsubmit="the_vendors_code();>

<input type="text" name="fielda" value="" >
<!-- several more fields -->

<!-- my code -->
<SCRIPT type="text/javascript" SRC="xxx.js"></SCRIPT>
<SCRIPT type="text/javascript">
function popupForm(myForm, windowName)
{
var scrny=0 ;
var scrnx=200
<-! code to set scrny and scrnx based on browser -->
fielda_h.value = fielda.value ;
<!-- etc ..>

<!-- here's the place I need help -->
newWin= window.open("myPopup.php", windowName, 'height=600,width=550,and a whole bunch of other parameters') ;
newWin.moveTo(scrnx, scrny) ;
myForm.target=windowName;
return true ;
}
</script>

<input type="hidden" name="fielda_h" >
<input type="button" name="preview" value="See Preview" onClick="popupForm(this, 'join')"/>


Note that some of the code was taken from examples found on the net, so there's not a ton of originality here. :rolleyes:

So, again, just to restate, I know how to do a submit button/form to do action=post, but I am trying to simulate it with a regular button as I cannot change the existing <form></form> construct.

Thanks for any and all pointers.

Old Pedant
06-14-2010, 11:26 PM
<SCRIPT type="text/javascript">
function popupForm(myForm, windowName)
{
var scrny=0 ;
var scrnx=200
<-! code to set scrny and scrnx based on browser -->
fielda_h.value = fielda.value ;

// open a *BLANK* WINDOW!!!!
newWin= window.open("", windowName, 'height=600,width=550,and a whole bunch of other parameters') ;
newWin.moveTo(scrnx, scrny) ;

// save form info:
var saveTarget = myForm.target;
var saveAction = myForm.action;
var saveMethod = myForm.method; // not needed if already post

// change form info:
myForm.target = windowName;
myForm.action = "myPopup.php";
myForm.method = "post"; // not needed if <form> was already post
myForm.submit( ); // invoke the form, submitting to the popup window

// restore form:
myForm.target = saveTarget;
myForm.action = saveAction;
myForm.method = saveMethod; // if used

return true ; // why does this matter? ordinary buttons ignore return value
}
</script>


NOTE: The vendor's code that occurs via onsubmit of the form is *NOT* invoked when you do this! Calling submit function directly bypasses the onsubmit. If you need it called, then do so before calling submit().

alan_b56
06-15-2010, 05:08 PM
thanks Old Pedant.

I came up with a not very elegant solution, but I got the desired results by
1) create cookies
2) open "hidden" html file which reads the cookies, populates the text boxes, and self-clicks the "submit" button, which
3) calls the .php and closes itself.

btw, the "return true" is just a (bad) habit I got in to.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum