By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,570 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

unable to access pop up window objects

P: n/a
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,locatio n=no,status=no,directories=no,toolbar=no,scrollbar s=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>";
}

Jul 23 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Lee
so***********@yahoo.com 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,locati on=no,status=no,directories=no,toolbar=no,scrollba rs=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.

Jul 23 '05 #2

P: n/a


Lee wrote:
so***********@yahoo.com 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,locati on=no,status=no,directories=no,toolbar=no,scrollba rs=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,locatio n=no,status=no,directories=no,toolbar=no,scrollbar s=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.m ycheck3.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);

}

Jul 23 '05 #3

P: n/a
so***********@yahoo.com wrote:
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.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jul 23 '05 #4

P: n/a


Matt Kruse wrote:
so***********@yahoo.com wrote:
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

Jul 23 '05 #5

P: n/a
<so***********@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...


Matt Kruse wrote:
so***********@yahoo.com wrote:
>>> 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:opener.newWindowHtml;',
'windowName'
'...attributes...'
);

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #6

P: n/a
Grant Wagner wrote:
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:opener.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.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jul 23 '05 #7

P: n/a
Lee
so***********@yahoo.com 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().

Jul 23 '05 #8

P: n/a
ASM
so***********@yahoo.com wrote:

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,locatio n=no,status=no,directories=no,toolbar=no,scrollbar s=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="<input type=hidden name=a1>";
//alert("display elements" + display.document.elements);
and, of course :
message+="<font face='verdana,arial,helvetica,sans-serif' size=2>"+
"<table>";
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.m ycheck3.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 ?

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #9

P: n/a
ASM
so***********@yahoo.com wrote:

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)

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #10

P: n/a
Lee
so***********@yahoo.com said:

Matt Kruse wrote:
so***********@yahoo.com wrote:
>>> 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[i] + "</td>");
message.push("<td><input type='checkbox' ");
message.push("onclick=\"window.target.value=\'" +arguments[i] + "\';");
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:opener.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>

Jul 23 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Browse more JavaScript / Ajax / DHTML Questions on Bytes