Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if object exists

Status
Not open for further replies.

Samwell

Programmer
Jun 12, 2003
1
US
Hi All,

I am a novice when it comes to javascript so this may be very simple. In the code below, I want to be sure parent.main.document.forms[0].w_customer exists before the code executes. We use frames for our app and sometimes main is a but slow to load. When that happens we get the error "parent.main.document.forms[0].w_customer is null or not an object". How can I check to make sure parent.main.document.forms[0].w_customer is an object?

function chgfocus() {
if (***CODE TO GO HERE***) {
if (parent.main.document.forms[0].w_customer.value == '')
parent.main.document.forms[0].w_customer.focus();
else
parent.oetoolbar.document.forms[0].w_part.focus();
}
}
 
I think you can't check it becouse when you try to access it and it's not there yet it will through an error

what you can do though is to send a message from you loading frame when it's loaded ...

so your slow loading frame will call chgfocus()

Sergei
 
I would suggest creating a global variable at the top of your page and setting it to "false." At the bottom of the page (or at the bottom of the form) set the variable to true. Then, if the global variable's name is, for instance, frmIsLoaded, you could do:

if (frmIsLoaded)
{

//execute your code
}

I also agree with Sergei's suggestion of putting the function call below the form.

Good luck.
 
I think this should work.

If ( object) {
// do this
}

Like I have this kind of code at many a places as follows

if(document.list_form._VER_CERT){
document.list_form._VER_CERT.focus() ;
}

Where _VER_CERT is an object. So try the same thing with your object. It might work.

Thanks,
Shanthi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top