Page 1 of 1

Javascript question

Posted: Fri Aug 07, 2009 12:44 pm
by ConvertFromOldNGs
by sbarrett >> Fri, 3 Dec 2004 2:01:46 GMT

This is a long shot - but here goes:
I'm executing the following excerp of javascript on the submit of a 'popup' window (here 'opener' is the parent browser window)
.....
window.opener.JadeForm.submit();
window.close();
return;
}
.....

In IE I find it works fine, but in Netscape Navigator v 7.xx, it fails to submit the opener, and fails to close the popup window. I can assertain the client browser type and execute different code dependant on that, but does anyone know what alternative code might work for NN?

Thanks,
Tim

Re: Javascript question

Posted: Fri Aug 07, 2009 12:44 pm
by ConvertFromOldNGs
by Tim Hollobon >> Mon, 6 Dec 2004 3:08:28 GMT

Self answered: the code needs to be

window.opener.document.forms[0].submit();

not

window.opener.jadeform.submit();

in order to be compatable with Netscape/Mozilla.

Re: Javascript question

Posted: Fri Aug 07, 2009 12:44 pm
by ConvertFromOldNGs
by Stephen >> Tue, 7 Dec 2004 3:59:10 GMT

That works if you have only 1 form on the page, otherwise you need to try and keep track of which form corresponds to what number.
Eg. Home page may have one form for logon, one form for a "tell us where you are from", one for a password reminder etc...

I prefer to always use the name of the form much like you did in your first example. It makes the code much easier to read too.

window.opener.findObj("JadeForm").submit();

Where the method findObj is:

function findObj(n, d) {
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers.document); return x;
}

And that doesn't matter what browser its running on. And it can be used to find a form, texbox value, checkbox, radio button selection etc...