Reputation: 113
I've had a quick look but cannot find a specific answer for this query so thought I'd ask the experts. I'm still learning HTML and Javascript.
I have some code where I'm using the standard "body onLoad" function to run an "initialise" function located in the HTML doco head section. I have another function called "populateList(){...}" in the head which basically populates an array with data from an external file.
I want to initialise this list by calling the "populateList" function from within the "initialize" function. I've tried using populateList(); and other permutations but this doesn't seem to work. I assume this is a syntax query and should be straightforward so haven't included any code but will if it makes this clearer. Does the "populateList" function need to be specified before the calling function or does it iterate through functions before loading.
Thanks
Upvotes: 0
Views: 41
Reputation: 1188
Like this?
<html>
<head>
<script>
function initialise()
{
alert('initialise');
populateList();
}
function populateList()
{
alert('populate list');
}
</script>
</head>
<body onload="initialise()">
</body>
</html>
Demo: http://plnkr.co/edit/5HgzbiIHDXUijdSGSTzO?p=preview
If thats the case, Javascript works by loading scripts from top to bottom - so you will need to declare them in order.
Upvotes: 1