function Form2Popup(params, actionUrl, name, popupConfig, get) {
// free in choice: post or get
var method = (get == undefined || !get) ? 'POST' : 'GET';
// it's important to assign non-null name!
if (name == undefined || name == '') {
name = 'tmpPopup';
}
var form = document.createElement('<form action="' + actionUrl + '" method="' + method + '" target="' + name + '" style="display:none;"></form>');
var element = null;
for (var propName in params) {
element = document.createElement('<input type="text" name="' + propName + '" value="' + params[propName] + '">');
form.appendChild(element);
}
document.body.appendChild(form);
// First, open empty window: why make redundant request to server?
var win = window.open('about:blank', name, popupConfig);
// in order to restore this window
// if it's already been opened before
win.focus();
form.submit();
form.removeNode(true);
return win;
}
.......
// Example:
var _name = document.getElementById("nameDiv");
var _text = forms['myform'].messageTextarea.value;
var params = {name:_name,title:"user preview",txt:_text};
var previewPopup = Form2Popup(params, 'save.jsp?preview=1', 'preview', 'top=100,left=100,scrollbars=1');