problem with document.getElementById();

Even though there exists an element by name 'outbox' in my style sheet, the getElementById() fails to return the handle... plz explain me why...
this is bugging me since 7 days...

here i need to do 2 things
1. i need to write some data to the window using window.document.write,
2. i need to dynamically add elements to the window.

my code looks like :

function on_click(){
//second_call();

mywind=window.open("chrome://window/content/style.xul", "Message", "chrome,scrollbars=1,height=300,width=800");

mywind.document.open();

mywind.onload = myLoad(); // () is needed as i used the open function in the above line
}
If i dont use the open i cant use the write function...
the thing is i need to both write as well as add elements dynamically..

function myLoad(){

alert('loaded');

cur = mywind.document.getElementById('outbox');
boxEl = mywind.document.createElement('hbox');
cur.appendChild(boxEl);
var textEl = mywind.document.createElement('description');
boxEl.appendChild(textEl);
textEl.setAttribute('value','india');

}
the style sheet is :

<?xml version="1.0"?>

<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window id="example-window" title="Example 2.2.1"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >

<popupset>
<menupopup id="clipmenu">
<menuitem label="Cut"/>
<menuitem label="Copy"/>
<menuitem label="Paste"/>
</menupopup>
</popupset>

<vbox id='outbox'>
</vbox>

</window>
[1893 byte] By [gsatyaprakash] at [2007-11-20 11:16:52]
# 1 Re: problem with document.getElementById();
It would seem to me that the variable mywind would not be passed between the functions. Remember that variables first created in functions are for that function only. Try...

var mywind;
function on_click(){
//second_call();
mywind = window.open("chrome://window/content/style.xul", "Message", "chrome,scrollbars=1,height=300,width=800");

mywind.document.open();

mywind.onload = myLoad(); // () is needed as i used the open function in the above line
}

function myLoad(){
alert('loaded');

cur = mywind.document.getElementById('outbox');
boxEl = mywind.document.createElement('hbox');
cur.appendChild(boxEl);
var textEl = mywind.document.createElement('description');
boxEl.appendChild(textEl);
textEl.setAttribute('value','india');
}
PeejAvery at 2007-11-8 0:43:20 >
# 2 Re: problem with document.getElementById();
sorry for not mentioning that i declared the mywind variable global...
that's the reason i havent passed it...
gsatyaprakash at 2007-11-8 0:44:17 >
# 3 Re: problem with document.getElementById();
Using either Firebug or Firefox, have you tried to debug it? Where does it fail? What is the error?
PeejAvery at 2007-11-8 0:45:20 >
# 4 Re: problem with document.getElementById();
I m actually working with thunderbird...
i have an built-in error console... that says the cur has no properties...
is there a better debugging tool for thunderbird ? plz lemme kno...
gsatyaprakash at 2007-11-8 0:46:18 >
# 5 Re: problem with document.getElementById();
is there a better debugging tool for thunderbird ?
Not to my knowledge.

Try calling the window.open function in the same function as the getElementById() reference. That will let us know if it is failing because of the window call in separate functions.
PeejAvery at 2007-11-8 0:47:20 >
# 6 Re: problem with document.getElementById();
thank you...
gsatyaprakash at 2007-11-8 0:48:19 >
# 7 Re: problem with document.getElementById();
You're welcome. Good luck with the rest of your project! :wave:
PeejAvery at 2007-11-8 0:49:27 >