One for you javascript experts.
I have a highly complex form. When the user clicks the submit button, I would like a new window to be opened with a specific width and height. In order to achieve this, I have been hand constructing my query string, appending to my URL, and then using window.open. That is:
Very nasty, and very prone to error. Is there no way of using myform.sumbit() to the same effect. I had tried using submit and immediately resizing the new window, but this looked nasty as well :-( Ideas anyone?
Thanks, Neil
I have a highly complex form. When the user clicks the submit button, I would like a new window to be opened with a specific width and height. In order to achieve this, I have been hand constructing my query string, appending to my URL, and then using window.open. That is:
Code:
// create a query string
var query = "?";
var separator = "&";
var inputs = document.getElementsByTagName('INPUT');
for(var i = 0; i < inputs.length; i++) {
if(i > 0) query += separator;
query += inputs[i].name + "=" + escape(inputs[i].value);
}
inputs = document.getElementsByTagName('input');
for(var i = 0; i < inputs.length; i++) {
if(i > 0) query += separator;
query += inputs[i].name + "=" + escape(inputs[i].value);
}
// assume only one selection allowed
// this code will need to be modified if selects
// are designed to allow multiple selections
var selects = document.getElementsByTagName('SELECT');
for(var i = 0; i < selects.length; i++) {
if(i > 0) query += separator;
var select = selects[i];
var option = select.options[select.selectedIndex];
query += select.name + "=" + escape(option.value);
}
selects = document.getElementsByTagName('select');
for(var i = 0; i < selects.length; i++) {
if(i > 0) query += separator;
var select = selects[i];
var option = select.options[select.selectedIndex];
query += select.name + "=" + escape(option.value);
}
// open window
var width = (screen.width / 3) * 2;
var height = (screen.height / 3) * 2;
var left = (screen.width - width) / 2;
var top = (screen.height - height) / 2;
var features = "menubar=yes,left="+left+",top="+top+",width="+width+",height="+height;
window.open("ReportRequest"+query, null, features);
Thanks, Neil