0
<script type="text/javascript">
    aLabe = document.getElementById('alabel') ;
    function init(){
         aLabe.innerHTML= "asdf" ;
    }
</script>
<body onload="init()">
<div id="container">
    <div id="header" > Google maps Intro 1</div>
    <div id="alabel">Yo!!</div>
    <div id="map_canvas"></div>
</div>
</body>

In the above,line 4 throws an aLabe is null error. Why is this? isn't aLabe a global var which is called before init()? If so then why doesn't init have access to aLabe ?

Edited by kutchbhi: n/a

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by kutchbhi
0

What you are doing is, before the page is done loading, you are looking for a control called alabel. Because the page is not done loading (the control has not been rendered), it can not find the control. So now aLabe is null.

You either want to put line 3 inside the init function or put the script at the end of the page (just before the closing body tag).

0

Oh! so its not that the aLabe isn't available inside the function , its just that the var aLabe is null, because its being called before our div#label exists on the page. Thanks much for clearing this up for me.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.