Results 1 to 5 of 5

Thread: Javascript - getElementById(...) is null

  1. #1
    Funking Prink! Raz316's Avatar
    Join Date
    Jul 2003
    Location
    Deal, Kent, UK
    Posts
    2,978
    Thanks
    130
    Thanked
    62 times in 52 posts

    Javascript - getElementById(...) is null

    This is beginning to annoy me!

    I've got a webpage that's a grid of sections. Each section has a preview view and an edit view which contains a form. When I have an edit view open, all other sections display the preview.

    Now, when I move away from a section to another I have it run a javascript function that updates the relevant preview based on the new information in the form. This works fine. However, when I try to run this function when the page loads initially, I get errors stating that it cannot find the form fields in question. Now this would make sense because the forms are created via an ajax call, however the update function is getting run after the ajax call, I've tried a window.setTimeout after the construction of the page before trying to update the previews and I get the same.

    Anyone experienced similar with this? Any ideas?

    Thanks
    Last edited by Raz316; 25-07-2008 at 11:38 AM.

  2. #2
    Senior Member
    Join Date
    May 2007
    Location
    Cheshire
    Posts
    329
    Thanks
    16
    Thanked
    41 times in 25 posts
    • chadders's system
      • CPU:
      • Sony Vaio VGN-AW11Z/B
      • Operating System:
      • Windows 7 x64
      • Monitor(s):
      • Samsung 226BW + Belinea 17" lcd
      • Internet:
      • Be Pro - 14000/1200 (down/up kps)

    Re: Javascript - getElementById(...) is null

    Off the top of my head (a handy place to put things), you say the "update function" is run AFTER the "ajax call"...

    If you run the ajax call "asynchronously" then you'll need the "update func" to wait until the call is complete, or have the ajax call made synchronously"

  3. Received thanks from:

    Raz316 (25-07-2008)

  4. #3
    Funking Prink! Raz316's Avatar
    Join Date
    Jul 2003
    Location
    Deal, Kent, UK
    Posts
    2,978
    Thanks
    130
    Thanked
    62 times in 52 posts

    Re: Javascript - getElementById(...) is null

    Wahay, it seems so obvious now I did a bit of digging and found out how to turn off async within jquery.

    Thanks for that!

  5. #4
    Senior Member
    Join Date
    May 2007
    Location
    Cheshire
    Posts
    329
    Thanks
    16
    Thanked
    41 times in 25 posts
    • chadders's system
      • CPU:
      • Sony Vaio VGN-AW11Z/B
      • Operating System:
      • Windows 7 x64
      • Monitor(s):
      • Samsung 226BW + Belinea 17" lcd
      • Internet:
      • Be Pro - 14000/1200 (down/up kps)

    Re: Javascript - getElementById(...) is null

    No worries, but with running synchronously it could lock up the whole browser whilst waiting.

    Running asynchronously, you should be able to specify the code to run "when the async call completes".

  6. #5
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Javascript - getElementById(...) is null

    If you are using jquery you can easily register a callback function for any of its states (error, success, complete). Also you shouldn't need to use getElementById, and use jquerys css3 selector syntax ($('#my_id')).
    To err is human. To really foul things up ... you need a computer.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 6
    Last Post: 22-11-2006, 02:58 PM
  2. Replies: 2
    Last Post: 06-11-2006, 12:05 PM
  3. SQL Server 2005..
    By Stoo in forum Software
    Replies: 8
    Last Post: 03-02-2006, 02:05 PM
  4. null is not a null !
    By bogart in forum Software
    Replies: 7
    Last Post: 10-03-2005, 01:30 PM
  5. Creating databases using PHP?
    By Nemeliza in forum Software
    Replies: 10
    Last Post: 22-11-2003, 10:45 PM

Posting Permissions

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