Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: IE 7 document.getElementById() error

  1. #1
    Join Date
    Jan 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation IE 7 document.getElementById() error

    I'm only getting the error in IE 7:

    "A Runtime Error has occured.
    Do You Wish to Debug?

    Line: 150
    Error: Object doesn't support this property or method."

    This is my Javascript function:

    Code:
    function updateTotal(i, b) {
    	// Declare the HTML
    	totalHTML=i;
    	// Find the table cell
    	total=document.getElementById('total'); // THIS IS LINE 150
    	// Enter the HTML into the cell
    	total.innerHTML=totalHTML;
    	document.dayPlacement.subTotal.value=b;
    }
    I know it's a valid Id:

    Code:
    <tr>			
    	<td height="47"></td>
    	<td><b>Sub - Total:</b></td>
    	<td><div align="right"><b id="total">0.00</b></div></td>
    </tr>
    I'm drawing a complete blank. Any help would be had. Also, it works just as expected in FireFox

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Where is the script located?
    If it's:

    • In the head, it's fine
    • In the body above the div, it won't work. It won't have any properties. The div must be defined first.
    • In the body below the div, should be fine


    Hope that helps. Let us know if you have any more problems.
    - Mike

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    In the head, it's fine
    Code in the head is executed before any of the body is loaded.

    You must make sure that the <div> exists before doing anything with it. Where do you call this function?
    Also:
    Code:
            document.dayPlacement.subTotal.value=b;
    This is highly non-standard. Use:
    Code:
    document.forms['dayPlacement'].elements['subTotal'].value = b;
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code in the head is executed before any of the body is loaded.
    Yes, but when the code is within a function, it is ignored until called. So basically it reads the DIV before the function.
    Even if you called the function:
    Code:
    window.onload = function() {updateTotal(i value,b value);}
    It would still work.
    - Mike

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    As I said, depending on where the function is called. Calling it onload like that is fine, but it could be called in the global scope in the head, or in the body before the <div> has been loaded.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Jan 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    Code in the head is executed before any of the body is loaded.

    You must make sure that the <div> exists before doing anything with it. Where do you call this function?
    It's called in the body, as an onChange event handler

    Also:
    Code:
            document.dayPlacement.subTotal.value=b;
    This is highly non-standard. Use:
    Code:
    document.forms['dayPlacement'].elements['subTotal'].value = b;
    Sorry bout that... pretty new to JS, I'll change that over and start doing it that way.

    Quote Originally Posted by mburt View Post
    Where is the script located?
    If it's:

    • In the head, it's fine
    • In the body above the div, it won't work. It won't have any properties. The div must be defined first.
    • In the body below the div, should be fine


    Hope that helps. Let us know if you have any more problems.
    Right now it's in the body above the Div, but I changed it to the body below the Div and it still isn't working... same error.

  7. #7
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    They way you had it first should work...
    I think we've realized that it isn't the problem. Maybe a bug in IE? I'm not sure.
    - Mike

  8. #8
    Join Date
    Jan 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Even when I tell IE to ignore this JS problem, it comes up with another, exact same thing. Elsewhere in the page I tell it to change the contents of a certain element, using the getElementById() function, but it doesn't work, same error.

  9. #9
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Is the table within a form?
    - Mike

  10. #10
    Join Date
    Jan 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes, the table is within the form.

Bookmarks

Posting Permissions

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