Jump to content

Initialization


Stopofeger

Recommended Posts

Hi there,

One thing i still dont understand about javascript is exctly when all the objects are initialized.

for example if i try to access form elements from the head tags.
the objects are still undefined and error comes saying the object is null.
so exactly where shud i place my js so the element objects gets ready.
Link to comment
Share on other sites

You will want to add an onLoad event handler to call your JavaScript when the page is fully loaded, otherwise your JavaScript will be run before the the rest of the web page is loaded and thus you get the error messages you are getting. Example:

[code]<html>
<head>
<script type="text/javascript">
/* this function will be called when the page is loaded */
function load()
{
    alert("Page is loaded");
}
</script>
</head>
<!-- The event handler: -->
<body onload="load()">

<h1>Page content</h1>

page content here. page content here. page content here. page content here.
page content here. page content here. page content here. page content here.
<br /></br />
page content here. page content here. page content here. page content here.
page content here. page content here. page content here. page content here.
page content here. page content here. page content here. page content here.
page content here. page content here. page content here. page content here.
<br /><br />
page content here. page content here. page content here. page content here.
page content here. page content here.

</body>

</html>[/code]
Link to comment
Share on other sites

Yes thats what i do.
But there is sometimes when i have to do things before the document is fully loaded.
So my question is, which objects can i use before the page loads?
definetly not document object, its null.
that leaves me with only predefined objects like Array, Date etc. Btw can i use window obj before loading?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.