Stopofeger Posted December 24, 2006 Share Posted December 24, 2006 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. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted December 24, 2006 Share Posted December 24, 2006 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] Quote Link to comment Share on other sites More sharing options...
Stopofeger Posted December 26, 2006 Author Share Posted December 26, 2006 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? Quote Link to comment Share on other sites More sharing options...
emehrkay Posted December 26, 2006 Share Posted December 26, 2006 i wouldnt attach it to the body tag. do thisonload = function(){funtionA();functionB();}or onload = functionA; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.