Friday, December 12, 2008

Javascript Form Submit Using POST action Into a new Window

<form> element of html have several attributes for controlling submission

method : get or post
action : the url for the post back action
target : the target for the post back action, _blank, _parent, _self, _top, name of a window
name : name of the form

In this topic of using javascript to change POST action of a form so that it post into a new Window, action and target is the most important attribute here.

you can use javascript function window.open(url, name, param)
e.g. window.open(test.html,'','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');

to post into another window, we will set the action to the url of the new window and target is the name of the new window.
e.g.

function PostToNewWindow()
{
    form.action = 'newForm.asp?action=submit&param=new'; //any valid url and query string
    form.target = 'NewPopupForm'; // name of the new form
    window.open('', 'NewPopupForm', 'height=50, width=50, resizable = no, toolbar=no, status=no');
    form.submit;

}

No comments: