Thursday, 26 March 2015

How to post a form (from parent window) to window popup (child window)

I was just trying to open a new window popup and condition was to send parametes to the child window (popup having some fixed width and height) by posting a form.

While searching on google, I found few suggestions like -
put target="_blank" in form but this will open a new tab

Finally, I have written following code which serves the purpose.

Below code is submitting form to popup window "Details" after clicking on link.

show_details() is function which is opening windwo with same name that we have specified form attribute "target" i.e. "details_popup" which has fixed height and width as per our requirement.

Code :


<a name="submit_form_link" href="javascript:show_details()">
<form name="frmTempSearchResult" id="frmTempSearchResult" action="Details.cfm#" method="post" target="details_popup">
                <input type="hidden" name="frmId" value="">
                <input type="hidden" name="frmUsername" value="ds">
                <input type="hidden" name="frmPassword" value="ds">
</form>

<script type="text/javascript">
                function show_details()
                {                                             
                                window.open('', 'details_popup', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=1100, height=700, top='+((screen.width/2)-(1000/2))+', left='+((screen.height/2)-(900/2)));
                                document.frmTempSearchResult.submit();
                }
</script>