[Project_owners] Javascript!
Matthew Wilson
matthew at mjwilson.demon.co.uk
Sat Oct 25 15:05:35 PDT 2008
In example 2, you call p.Initial() too early. The document has not yet
been fully loaded, so document.getElementById("iddd") does not return
anything.
Matthew
joe ertaba wrote:
> There is a problem with this method which I cant find out, here is example:
>
> Example 1 (This example works fine)
>
> --JS code---
>
> var p = {
> element1 : "" ,
> Initial : function(){
> this.element1 = document.getElementById("iddd");
> },
> MyFuction : function(){
> this.element1.value="some text";
> }
> }
>
> -----
> -XUL code----
>
> <label value="Put your XUL here!" id="iddd"
> onclick="
> *p.Initial();
> *
> *p.MyFuction();*
> "
> />
> -----
>
> Example 2:
>
> --JS code---
>
> var p = {
> element1 : "" ,
> Initial : function(){
> this.element1 = document.getElementById("iddd");
> },
> MyFuction : function(){
> this.element1.value="some text";
> }
> }
>
> *p.Initial();
> window.addEventListener("load", p.MyFuction, true); *
> -----
> -XUL code----
>
> <label value="Put your XUL here!" id="iddd"/>
> -----
>
> The second example DOES NOT work!
>
>
>
>
>
>
> On Sat, Oct 25, 2008 at 8:23 PM, Roberto Bouzout (tito) <zilla at nxuy.com
> <mailto:zilla at nxuy.com>> wrote:
>
> You are welcome! :)
>
>
> joe ertaba wrote:
>
> I find out that when I use initial function to initialize var
> then it works!
>
> Thanks for your help
>
>
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org <mailto:Project_owners at mozdev.org>
> https://www.mozdev.org/mailman/listinfo/project_owners
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> https://www.mozdev.org/mailman/listinfo/project_owners
More information about the Project_owners
mailing list