Login | Register | FAQ

Calling an Initialization Function on Page-load

+ Post a reply

Page 1 of 1

Calling an Initialization Function on Page-load

by mike_c » Sun Feb 17, 2013 12:05 pm

Hey. I'm very new to JavaScript (just been learning it for a few weeks) and I'm currently working through the tutorials on this site - which are great; well written and make things really easy to understand.
As I'm learning the ins and outs of the language, there are a few questions that are coming up which I thought might be good to ask you guys on this board, one of which is:

When you create an initialization function and then set it to run when the page loads, all the tutorials so far have been putting this onload trigger after the init() function itself like so:

function init()
var myForm = document.getElementById("myForm");
myForm.onsubmit = validate;

onload = init;

I've tried running the script with the onload trigger above the function definition and it seems to work fine, no difference at all. So does it matter what order you put them in?
I ask this because since the page's onload event is the first thing that happens, I was thinking maybe the onload trigger should go first? Also, it seems that in most other cases, when a function is called, usually the function block of code goes after the call (at least when its called the first time).

This is a pretty basic question, but I was just wondering if it has implications for calling functions based on other page events. I did a search on the board and it doesn't look like this question has already been asked, so I wondered if you might be able to help.

Thanks for reading!
User avatar


  • Posts: 1
  • Joined: Wed Feb 06, 2013 8:58 pm

Re: Calling an Initialization Function on Page-load

by XainPro » Mon Feb 18, 2013 4:18 pm

Well it dose not matter because it will trigger the event after loading all the code of body tag
so tactically it is function is loading after it is being triggered
But i Think its good to write function before calling it.
User avatar


  • Posts: 2401
  • Joined: Fri Feb 17, 2012 8:10 pm


by GeorgeHarPeale » Wed Aug 30, 2017 4:03 am

https://bitbucket.org/snippets/porfirio ... o2/R8Ldyk/
https://www.flickr.com/groups/3942007@N ... 636796964/

https://www.flickr.com/groups/3530434@N ... 136381075/

This is one of the best photography apps available to play on mobiles and it is developed by the famous Dec 21, 2016 Download your copy FREE! Best Do you want to suggest some improvement to Kdenlive the Free Video Editor?

I tried the iPlayer-Grabber in my G4 eMac (OS X 10.5.8) but it did not work. Note that this version is for PPC Macs OS X 10.4+ only. AdobeВ® FlashВ® Player, 10 or photoshop adobe reader adobe flash player accelerator android sdk dropbox realplayer skype iphoto zip virtualbox mozilla firefox mac os x 10.5.8 download
http://www.pianoclubhouse.com/community ... pid1531815
http://askar.icyboards.net/showthread.p ... #pid113365
http://jwch.info/viewtopic.php?f=11&t=1 ... 51#p243851
http://community.purepredictive.com/sho ... 6#pid77976
http://elarreglapedos.com/foros/viewtop ... 2534#p2534

User avatar


  • Posts: 1820
  • Joined: Mon Jul 10, 2017 5:19 pm
  • Location: Iceland

+ Post a reply

Page 1 of 1