[variable1] has no properties

D

David

I am getting a Javascript error from Firefox 1.0.5 when I try to reference a
table within a window that has just been opened and written to. I get the
Javascript error "cartTable has no properties" where cartTable is the
variable I assigned the table reference to.

cartTable=winDVDCart.document.getElementById("cartTable")

Previous to this, I have just opened a new window, used the document.write
method to write some HTML into it, and then used the document.close method.
At that point I call a new function to add some extra things into the new
window and this is the first statement that gets run. It seems as if the
table isn't quite finished loading when I try to reference it and that is
causing problems. I am not getting any errors in IE6 and it is working just
fine. I figured that maybe I could implement a loop to just wait until the
table is fully loaded but that will just loop infinitely for some odd
reason.

while (!winDVDCart.document.getElementById("cartTable")) {}

This code just loops infinitely, but if I just put an alert within the {}
for the while loop, it shows the alert once, I click ok and everything works
great after that. Could anyone point me in the right direction on this?

Thanks,

David
 
A

ASM

David said:
I am getting a Javascript error from Firefox 1.0.5 when I try to reference a
table within a window that has just been opened and written to. I get the
Javascript error "cartTable has no properties" where cartTable is the
variable I assigned the table reference to.

cartTable=winDVDCart.document.getElementById("cartTable")

what is exactly this 'winDVDCart' ?
if a name of frame (or iframe) :

cartTable=parent.winDVDCart.document.getElementById("cartTable")

if self main window name :
cartTable=document.getElementById("cartTable")

while (!winDVDCart.document.getElementById("cartTable")) {}

probably if you insert your JS and its code
after </table> the 1st way would run.
 
D

David

ASM said:
what is exactly this 'winDVDCart' ?
if a name of frame (or iframe) :

cartTable=parent.winDVDCart.document.getElementById("cartTable")

if self main window name :
cartTable=document.getElementById("cartTable")

winDVDCart is the handle to the window that was opened
probably if you insert your JS and its code
after </table> the 1st way would run.

This is not possible unless I insert a call to this function from a <script>
tag that is located after the </table>. This is all dynamic and thus part
of a big long string that gets written to the window when it is open.
Without explaining all the details, I'll suffice it to say that this is not
a desirable way of doing, though it is possible, it is a method I would
prefer to save as a last resort.

Any other ideas?
 
R

Randy Webb

David said the following on 7/19/2005 9:52 PM:
This is not possible unless I insert a call to this function from a <script>
tag that is located after the </table>. This is all dynamic and thus part
of a big long string that gets written to the window when it is open.
Without explaining all the details, I'll suffice it to say that this is not
a desirable way of doing, though it is possible, it is a method I would
prefer to save as a last resort.

Any other ideas?

Set an onload event handler for the new window:

winDVDCart.onload = functionToCall;

And have functionToCall be the continuation function where it gets a
reference to the table.
 
R

RobG

David said:
winDVDCart is the handle to the window that was opened




This is not possible unless I insert a call to this function from a <script>
tag that is located after the </table>. This is all dynamic and thus part
of a big long string that gets written to the window when it is open.
Without explaining all the details, I'll suffice it to say that this is not
a desirable way of doing, though it is possible, it is a method I would
prefer to save as a last resort.

Any other ideas?

You could use setTimeout to call the remainder of your function. That
should enable enough of a delay to allow the table to be accessed.

function openWindow(...){
winDVDCart = window.open(...);
winDVDCart.document.write( ... )
...
winDVDCart.document.close();

setTimeout( function () {
// do whatever
}, 10 );
}

Or you could put the rest of the script into a different function and
call that, either directly or with setTimeout (be careful with closures).
 
D

David

Randy said:
Set an onload event handler for the new window:

winDVDCart.onload = functionToCall;

And have functionToCall be the continuation function where it gets a
reference to the table.

Well this seems to work fine in both browsers now, definitely not how I'd
like to do it, but I guess it works. Thanks for the help, and as for the:

winDVDCart.onload = functionToCall;

see my post in this group under the name "Adding events dynamically". It
appears that Firefox 1.0.5 doesn't like this syntax and will only call the
function if you put parentheses after it as in

winDVDCart.onload = functionToCall();

which is definitely not correct syntax and should do something totally
different. Anyway, just thought I'd add that on a side note.

Thanks again,

David
 

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,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top