SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IE error: "Object doesn't support this property or method"

    So, I got my script to work fine in Firefox but running it in IE 7 generates "object doesn't support this property or method" on the first assignment in the script (taxiFuelGal = 1.5):
    Code:
    var Compute =
    {
    	init: function()
    	{
    		taxiFuelGal = 1.5;
    		taxiFuelLbs = 6 * taxiFuelGal;
    		tksGal = 3;
    		tksLbs = tksGal * 9.2;
    The .init method is invoked only after the page has loaded (using the Core.js library from "Simply Javascript"). Google gives the impression this is a fairly common error that may be caused by a variety of things, but I wasn't able to find any reference to it here. I apologize in advance if this has been dealt with already, but I just couldn't find a reference. Any ideas or pointers? Thanks.

    Involute

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,681
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    A test shows that it seems to work as expected.

    Code javascript:
    <html>
    <head>
    <script>
    var Compute =
    {
    	init: function()
    	{
    		taxiFuelGal = 1.5;
    		taxiFuelLbs = 6 * taxiFuelGal;
    		tksGal = 3;
    		tksLbs = tksGal * 9.2;
    		alert(tksLbs);
    	}
    };
    window.onload = function () {
    	Compute.init();
    };
    </script>
    </head>
    <body>
    </body>
    </html>

    It's quite likely that it's something else with the page that's causing the problem.
    Link us to a test page on the internet and further troubleshooting can occur.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for looking at this. Here's the link to the page: http://www.karllautman.com/weather/WnB21.htm . Entries in the input boxes are summed to calculate Takeoff weight as soon as the entries change. Apologies for the Dreamweaver-related alignment problem on the last two lines. In Firefox, the fields are properly pre-loaded w/ values and the summing works fine. In IE 7 none of the fields are pre-loaded and the script fails.

    Involute

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,681
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    The biggest problem is that you have separate functions tat are trying to share information between each other.

    You'll need to use an object to hold the separate values, so that they can be referred to from the other functions.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Paul.

    1. Is that the main reason it doesn't work in IE? Why does it work in Firefox?

    2. Can you give me a simple example of an object that stores the values that the other functions access (just generically; I'm not asking you to re-write my code)? I thought that's what global values are for.

    Involute

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,681
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Firefox creates the variables as a part of the window object, whch does provide some kind of fallback but is still a bad idea as all the variables are available to everything, risking them being changed or accidentally used by something else.

    One way to keep the variables together is to gather them up into a consistant object.
    We can create a plane object to store the variables that you need to keep track of.

    Code javascript:
    var Compute =
    {
        plane: {},
        init: function()
        {
            var plane = Compute.plane;
            plane.taxiFuelGal = 1.5;
            plane.taxiFuelLbs = 6 * plane.taxiFuelGal;
            plane.tksGal = 3;
            ...

    The full name for tksGal would be Compute.plane.tksGal but we can shorten that by defining a local variable called plane that points to Compute.plane

    Then any function that wants to use variables from that plane object, we can define a local variable that points to Compute.plane, and access them from there.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That solved the problem. Thanks! Guess I'll steer clear of global variables in the future.

    Involute


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
  •