unable to access pop up window objects

S

soup_or_power

The pop up window has several checkboxes. I'm unable to access the
checkboxes using the handle from window.open. Any way to do this?

var display;
function showSugg(but_id, sugg1, sugg2, sugg3, sugg4, sugg5) {



display=window.open('','_blank','menubar=0,location=no,status=no,directories=no,toolbar=no,scrollbars=yes,height=150,width=190')

var message="<font face='verdana, arial, helvetica,
san-serif' size='2'><table>";
message += "<tr><td>" + sugg1 + "</td> <td><input
type=checkbox name=mycheck1 value=\'" + sugg1 +
"\' onClick=\"self.opener.document.forms[0]." + but_id +
".value=\'" + sugg1 + "\';"
+ "document.mycheck2.checked=false;mycheck3.checked=false;" +
" mycheck4.checked=false;" +
"mycheck5.checked=false;" + "\"></td></tr>";
}
 
L

Lee

(e-mail address removed) said:
The pop up window has several checkboxes. I'm unable to access the
checkboxes using the handle from window.open. Any way to do this?

var display;
function showSugg(but_id, sugg1, sugg2, sugg3, sugg4, sugg5) {



display=window.open('','_blank','menubar=0,location=no,status=no,directories=no,toolbar=no,scrollbars=yes,height=150,width=190')

var message="<font face='verdana, arial, helvetica,
san-serif' size='2'><table>";
message += "<tr><td>" + sugg1 + "</td> <td><input
type=checkbox name=mycheck1 value=\'" + sugg1 +
"\' onClick=\"self.opener.document.forms[0]." + but_id +
".value=\'" + sugg1 + "\';"
+ "document.mycheck2.checked=false;mycheck3.checked=false;" +
" mycheck4.checked=false;" +
"mycheck5.checked=false;" + "\"></td></tr>";
}

The code you've shown us opens a blank window and then assigns a string
value to a variable named "message". There are no checkboxes.
 
S

soup_or_power

Lee said:
(e-mail address removed) said:
The pop up window has several checkboxes. I'm unable to access the
checkboxes using the handle from window.open. Any way to do this?

var display;
function showSugg(but_id, sugg1, sugg2, sugg3, sugg4, sugg5) {



display=window.open('','_blank','menubar=0,location=no,status=no,directories=no,toolbar=no,scrollbars=yes,height=150,width=190')

var message="<font face='verdana, arial, helvetica,
san-serif' size='2'><table>";
message += "<tr><td>" + sugg1 + "</td> <td><input
type=checkbox name=mycheck1 value=\'" + sugg1 +
"\' onClick=\"self.opener.document.forms[0]." + but_id +
".value=\'" + sugg1 + "\';"
+ "document.mycheck2.checked=false;mycheck3.checked=false;" +
" mycheck4.checked=false;" +
"mycheck5.checked=false;" + "\"></td></tr>";
}

The code you've shown us opens a blank window and then assigns a string
value to a variable named "message". There are no checkboxes.

Sorry. Here is the full code. Many thanks again:

var display;
function showSugg(but_id, sugg1, sugg2, sugg3, sugg4, sugg5) {



display=window.open('','_blank','menubar=0,location=no,status=no,directories=no,toolbar=no,scrollbars=yes,height=150,width=190')

var screen_height = window.screen.availHeight;
var screen_width = window.screen.availWidth;
var left_point = parseInt(screen_width / 2);
var top_point = parseInt(screen_height/2);
display.moveTo(left_point, top_point);
display.focus();
display.document.write("<input type=hidden name=a1>");
//alert("display elements" + display.document.elements);

var message="<font face='verdana, arial, helvetica, san-serif'
size='2'><table>";
message += "<tr><td>" + sugg1 + "</td> <td><input
type=checkbox name=mycheck1 value=\'" + sugg1 +
"\' onClick=\"self.opener.document.forms[0]." + but_id +
".value=\'" + sugg1 + "\';"
+ "self.opener.document.forms[0]." + but_id +
".style.backgroundColor=\'#ffffff\';"
+ "self.opener.document.forms[0]." + but_id +
".style.color=\'#000000\';"
+
"display.document.mycheck2.checked=false;display.mycheck3.checked=false;"
+
" display.mycheck4.checked=false;" +
"display.mycheck5.checked=false;" + "\"></td></tr>";

message += "<tr><td>" +sugg2 + " </td><td><input type=checkbox
name=mycheck2 value=" + sugg2 +
" onClick=\"document.forms[0]." + but_id + ".value=" + sugg2
+"\"></td></tr>";

message += "<tr><td>" +sugg3 + " </td><td><input type=checkbox
name=mycheck3 value=" + sugg3 +
" onClick=\"document.forms[0]." + but_id + ".value=" + sugg3 +
"\"></td></tr>";

message += "<tr><td>" +sugg4 + " </td><td><input
type=checkbox name=mycheck4 value=" + sugg4 +
" onClick=\"document.forms[0]." + but_id + ".value=" + sugg4
+ "\"></td></tr>";

message += "<tr><td>" +sugg5 + " </td><td><input
type=checkbox name=mycheck5 value=" + sugg5 +
" onClick=\"document.forms[0]." + but_id + ".value=" + sugg5
+ "\"></td></tr>";
message+="</table></font>";
//alert(message);
display.document.write(message);

}
 
M

Matt Kruse

What do you mean you're unable? What happens? What did you try? Where's the
code for that?
display.document.write("<input type=hidden name=a1>");

Before doing a write() you should do an open()
display.document.write(message);

And then you should do a close() after you're done.

Furthermore, your HTML in your popup is not valid. No html tag, no body tag,
no form tag, etc.

Then the real problem is that from within your popup code, you shouldn't be
referencing 'display'. Instead, just use document.forms[0].mycheck2, etc.
 
S

soup_or_power

Matt said:
What do you mean you're unable? What happens? What did you try? Where's the
code for that?
display.document.write("<input type=hidden name=a1>");

Before doing a write() you should do an open()
display.document.write(message);

And then you should do a close() after you're done.

Furthermore, your HTML in your popup is not valid. No html tag, no body tag,
no form tag, etc.

Then the real problem is that from within your popup code, you shouldn't be
referencing 'display'. Instead, just use document.forms[0].mycheck2, etc.

I added the display.document.open() and display.document.close(). Then
I have made the changes to refer to the checkboxes using
document.forms[0] as you suggested. I now get the error
"document.forms[0].mycheck2 has no properties"
on FireFox. This is in line with my expectation given that popup is
opened inside a function call. Are you suggesting I should use a form
in the display.document?

Thanks
 
G

Grant Wagner

Matt said:
I'm unable to access the
checkboxes using the handle from window.open.

What do you mean you're unable? What happens? What did you try?
Where's the
code for that?
display.document.write("<input type=hidden name=a1>");

Before doing a write() you should do an open()
display.document.write(message);

And then you should do a close() after you're done.

Furthermore, your HTML in your popup is not valid. No html tag, no
body tag,
no form tag, etc.

Then the real problem is that from within your popup code, you
shouldn't be
referencing 'display'. Instead, just use document.forms[0].mycheck2,
etc.

I added the display.document.open() and display.document.close(). Then
I have made the changes to refer to the checkboxes using
document.forms[0] as you suggested. I now get the error
"document.forms[0].mycheck2 has no properties"
on FireFox. This is in line with my expectation given that popup is
opened inside a function call. Are you suggesting I should use a form
in the display.document?

Thanks

The call to window.open() is asynchronous. There is no guarantee the new
window is open and has a -document- object available to call write() on
when in the milliseconds it takes to assemble the string after
requesting the new window be opened. Use this instead:

window.newWindowHtml = [
'<html>',
'<head>',
'<title>Title</title>',
'</head>',
'<body>',
'This is a test',
'</body>'
'</html>'
].join('\n');

var myWindow = window.open(
'javascript:eek:pener.newWindowHtml;',
'windowName'
'...attributes...'
);
 
M

Matt Kruse

Grant said:
The call to window.open() is asynchronous. There is no guarantee the
new window is open and has a -document- object available to call
write() on when in the milliseconds it takes to assemble the string
after requesting the new window be opened.

I'm not sure that's true. The only 'async' part of window.open is loading
the content.

Since a window object is returned from the call, that guarantees that the
window object is created and ready for access. Along with the window object
is a document object. It will always be there.

Even if it takes 5 seconds to load the content, you can still access the
document object, write to it, and close it. It just cancels the loading of
the content. If you can come up with any test case where there was no
available document object in the returned window object, I'd be interested
in seeing it.
var myWindow = window.open(
'javascript:eek:pener.newWindowHtml;',

Unfortunately, using the javascript: pseudo-protocol will cause security
alerts in IE under some circumstances. Otherwise, I would use it more. There
seems to be no good cross-browser, fire-proof way of opening a blank window
to contain dynamically-written content.
 
L

Lee

(e-mail address removed) said:
var screen_height = window.screen.availHeight;
var screen_width = window.screen.availWidth;
var left_point = parseInt(screen_width / 2);
var top_point = parseInt(screen_height/2);

In addition to the other suggestions you've received, don't use
parseInt() to truncate numbers. It acts on strings, so it has
to convert the value to a string, and then back to a number again.
use Math.floor() or Math.round().
 
A

ASM

Here is the full code. Many thanks again:

var display;
function showSugg(but_id, sugg1, sugg2, sugg3, sugg4, sugg5) {



display=window.open('','_blank','menubar=0,location=no,status=no,directories=no,toolbar=no,scrollbars=yes,height=150,width=190')

var screen_height = window.screen.availHeight;
var screen_width = window.screen.availWidth;
var left_point = parseInt(screen_width / 2);

var left_point = parseInt(screen.availWidth / 2);
var top_point = parseInt(screen_height/2);
display.moveTo(left_point, top_point);
display.focus();
display.document.write("<input type=hidden name=a1>");

better :
var message= said:
//alert("display elements" + display.document.elements);

and, of course :
message+="<font face='verdana,arial,helvetica,sans-serif' size=2>"+
var message="<font face='verdana, arial, helvetica, san-serif'
size='2'><table>";
message += "<tr><td>" + sugg1 + "</td> <td><input
type=checkbox name=mycheck1 value=\'" + sugg1 +
"\' onClick=\"self.opener.document.forms[0]." + but_id +
".value=\'" + sugg1 + "\';"
+ "self.opener.document.forms[0]." + but_id +
".style.backgroundColor=\'#ffffff\';"
+ "self.opener.document.forms[0]." + but_id +
".style.color=\'#000000\';"
+
"display.document.mycheck2.checked=false;display.mycheck3.checked=false;"

no : you are fixing a text readable IN display's page's code
so :
"document.mycheck2.checked=false; document.mycheck3.checked=false;"
+
" display.mycheck4.checked=false;" +

and so on :
"document.mycheck4.checked=false;" +
"document.mycheck5.checked=false;" +
"display.mycheck5.checked=false;" + "\"></td></tr>";

message += "<tr><td>" +sugg2 + " </td><td><input type=checkbox
name=mycheck2 value=" + sugg2 +
" onClick=\"document.forms[0]." + but_id + ".value=" + sugg2
+"\"></td></tr>";

message += "<tr><td>" +sugg3 + " </td><td><input type=checkbox
name=mycheck3 value=" + sugg3 +
" onClick=\"document.forms[0]." + but_id + ".value=" + sugg3 +
"\"></td></tr>";

message += "<tr><td>" +sugg4 + " </td><td><input
type=checkbox name=mycheck4 value=" + sugg4 +
" onClick=\"document.forms[0]." + but_id + ".value=" + sugg4
+ "\"></td></tr>";

message += "<tr><td>" +sugg5 + " </td><td><input
type=checkbox name=mycheck5 value=" + sugg5 +
" onClick=\"document.forms[0]." + but_id + ".value=" + sugg5
+ "\"></td></tr>";
message+="</table></font>";
//alert(message);
display.document.write(message);

with(display.document) {
open();
write(message);
close();
}

I find any <form> nor </form> in your message ... normal ?
 
A

ASM

I now get the error
"document.forms[0].mycheck2 has no properties"

of course : you have any form in your message

It'ld be better to create the complete html page you want to have in
your popup.

Then, if you prefer to use a *virtual* with its code wrotten by JS
try to use copy/paste from html to JS
on FireFox. This is in line with my expectation given that popup is
opened inside a function call. Are you suggesting I should use a form
in the display.document?

of course, a checkbox would be in a form

<cite>
document.mycheck2.checked=false;
</cite>

document.forms[0].mycheck2.checked=false;
here is checkbox named 'mycheck2' set in 1st form of document (message)
 
L

Lee

(e-mail address removed) said:
Matt said:
I'm unable to access the
checkboxes using the handle from window.open.

What do you mean you're unable? What happens? What did you try? Where's the
code for that?
display.document.write("<input type=hidden name=a1>");

Before doing a write() you should do an open()
display.document.write(message);

And then you should do a close() after you're done.

Furthermore, your HTML in your popup is not valid. No html tag, no body tag,
no form tag, etc.

Then the real problem is that from within your popup code, you shouldn't be
referencing 'display'. Instead, just use document.forms[0].mycheck2, etc.

I added the display.document.open() and display.document.close(). Then
I have made the changes to refer to the checkboxes using
document.forms[0] as you suggested. I now get the error
"document.forms[0].mycheck2 has no properties"
on FireFox. This is in line with my expectation given that popup is
opened inside a function call. Are you suggesting I should use a form
in the display.document?

The checkboxes that you're trying to uncheck are in the document in
the new window, but from within that window, they can't be referred
to as display.document...

Here's a version that does most of what I think you want.
Note that the screen positioning may only work in IE as written:

<html>
<head>
<script type="text/javascript">
var display=0;
function showSugg(but_id, sugg1, sugg2, sugg3, sugg4, sugg5) {
if(display && !display.closed) {
display.close();
}
var message= [ "<html><head><script type=\"text/javascript\">",
"window.target=opener.document.forms[0].",
but_id,
";<\/script><\/head>\n<body>",
"<font face='verdana,arial,helvetica,san-serif' size='2'>\n",
"<form action='http://www.google.com' name='frank'><table>\n"
]
for(var i=1;i<arguments.length;i++) {
message.push("<tr><td>" + arguments + "</td>");
message.push("<td><input type='checkbox' ");
message.push("onclick=\"window.target.value=\'" +arguments + "\';");
for(j=1;j<arguments.length;j++) {
if(j!=i) {
message.push("this.form.elements["+(j-1)+"].checked=false;");
}
}
message.push("\"></td></tr>\n");
}
message.push("</table></form><\/font><\/body><\/html>");
globalHTML=message.join("");
display=window.open("javascript:eek:pener.globalHTML",
"popup",
"resizeable,scrollbars,height=150,width=190");
var screen_height = screen.availHeight;
var screen_width = screen.availWidth;
var left_point = Math.round(screen_width/2);
var top_point = Math.round(screen_height/2);
display.moveTo(left_point, top_point);
display.focus();
}
</script>
</head>
<body>
<form>
Greek letter:
<input name="foo" value="omega">
<input type="button"
value="suggest"
onclick="showSugg('foo', 'alpha','beta','gamma','delta','epsilon')">
<br>
Fruit:
<input name="bar" value="lemon">
<input type="button"
value="suggest"
onclick="showSugg('bar', 'apple','banana','cherry')">
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,824
Messages
2,569,755
Members
45,745
Latest member
JohannaLev

Latest Threads

Top