--- Pablo Vázquez Blázquez <[EMAIL PROTECTED]> wrote:
> Anyone knows why my javascript code is executed at the loading of a page 
> instead when it *should*??

Mostly because of your definition of "should" ;)

> For example, I have a .jspx page with a form:
> <form>
>     ...
>     <input id="id" ...>
>     ...
> <form>
> 
> <script>
>     alert('hi');
>     alert(document.getElementById('id'));
> </script>
> 
> 'hi' is shown before the form and then 'undefined'.
> But my js code is at the end of the page. How can it be possible? 

Just because your JavaScript is at the end of the page doesn't mean the
entire page (thus the DOM) will be rendered before your JavaScript executes,
and it may be browser-dependent.

As was pointed out you can put your JavaScript in a window.onload section;
IIRC this will wait until *everything* has loaded, including images etc.

However, putting such JavaScript in an "window.onload" handler *may*
interfere with Dojo's own onload handler, which may do DOM rewriting and so
on. 

Instead try using Dojo's:

dojo.addOnLoad(aFunction)

where "aFunction" is either a function reference or an anonymous function.

See dojo.addOnLoad [1] and a short blog post [2] for some further
information.

Dave

[1] Dojo's dojo.addOnLoad function:
http://redesign.dojotoolkit.org/jsdoc/dojo/HEAD/dojo.addOnLoad
[2]
http://www.dev411.com/blog/2006/07/13/dojo-dojo-addonload-vs-body-onload-and-window-onload


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to