Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

javascript window.onLoad

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
TonyLB
LXF regular


Joined: Tue Apr 12, 2005 8:08 pm
Posts: 112
Location: Wirral, UK

PostPosted: Tue Feb 20, 2007 10:10 pm    Post subject: javascript window.onLoad Reply with quote

I've got an html page which fills several textboxes in a form with data from a database. Some php code initialises the arrays of data (correctly) and then javascript uses this to put the data into the input text boxes.

I've used window.onLoad() to call a javascript function which loads the first record. The first part of the relevant function is:
function fillRecord(){
obj = document.getElementById('name'); obj.value = Name[recordPos];

At first the data is not filled in and the js console reports that 'the element obj has no properties'. If I navigate back to the first record it does get filled in. I've investigated further and it seems as if the function gets called before the form is drawn. Shifting the window.onLoad() call to just before the <\body> tag solves it, but I thought that onLoad waited until the entire page was loaded. Or am I missing something obvious here? I didn't really want scraps of script through the document.

How can I force it to wait until the entire frame, including the form, is loaded and drawn?

Tony
Back to top
View user's profile Send private message
jpmcc



Joined: Wed Feb 21, 2007 8:54 pm
Posts: 2

PostPosted: Wed Feb 21, 2007 10:30 pm    Post subject: RE: javascript window.onLoad Reply with quote

Don't know if this will help, but marking a script element with the defer attribute would tell the browser that this code can safely wait until everything else is complete. That may have the effect that you are after.

e.g.
Code:

<script type="text/javascript" defer="defer">

some code...

</script>


Then in that block (which I guess could still be the in the head element), call the function to fill in your text fields.
Back to top
View user's profile Send private message
TonyLB
LXF regular


Joined: Tue Apr 12, 2005 8:08 pm
Posts: 112
Location: Wirral, UK

PostPosted: Sun Feb 25, 2007 12:51 pm    Post subject: RE: javascript window.onLoad Reply with quote

Thanks, I might give that one a go.

Tony
_________________
In the beginning was nothing, which exploded! (Lords and Ladies, Terry Pratchett)
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast