www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] very simple question.

  1. #1
    Join Date
    May 2007
    Location
    Surrey, UK
    Posts
    75

    resolved [RESOLVED] very simple question.

    can't get this very simple thing right even though I wrote some considerably more complex code yesterday. Please can you tell me what I am getting wrong?

    Code:
    document.onload = function() {
        alert("fired");
        var rating = getElementById("ratingField");
        if (rating == null) {
            alert("not null");
        }
    }
    the function isn't firing at all as far as I can tell, I get no alerts.

    I tried window.onload and if fires but document.onload isn't firing.

    thanks,
    Last edited by BrownWarrior; 04-05-2010 at 06:23 AM.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    May 2007
    Location
    Surrey, UK
    Posts
    75
    Okay thanks Fang!

    I haven't written any javascript in a while and I was sure that that code worked for me before! now I know why!! haha

    but is there an alternative? if I use window.onload it tells me that my line

    var rating = getElementById("ratingField");

    expects an object, I presume because it can't find ratingField because it hasn't been loaded.

    So what is the new technique of running scripts when the page has loaded?

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    window.onload = function() {
        alert(" fired");
        var rating = document.getElementById("ratingField");
        if (rating == null) {
            alert("not null");
        }
    };
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    May 2007
    Location
    Surrey, UK
    Posts
    75
    Thanks Fang,


    I'm still pretty new to javascript. Should start to remember these school boy errors soon. I'm starting to get a bit of satisfaction out of writing code now anyway, It's begginning to make sense!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles