Object doesn't support this property or method

Discussion in 'Javascript' started by Darkstar 3D, Jan 18, 2007.

  1. Darkstar 3D

    Darkstar 3D Guest

    Could I get some help on whats going on here. This thing worked in a
    previous incarnation. The only change (as my feeble memory recalls) was
    changes to the formating of the page.

    Help!

    http://www.thepurrfectnanny.com/map.php

    Code block that errors is:

    //Map Change function
    function changeMap(){
    //user_input = "kennesaw";
    user_input = "";
    for (i=0;i<document.forms[0].c1.length;i++) {
    if (document.forms[0].c1.checked) {
    user_input = document.forms[0].c1.value;
    }
    }
    city = user_input;
    onLoad(city);

    }
    Darkstar 3D, Jan 18, 2007
    #1
    1. Advertising

  2. Darkstar 3D

    Daz Guest

    Darkstar 3D wrote:

    > Could I get some help on whats going on here. This thing worked in a
    > previous incarnation. The only change (as my feeble memory recalls) was
    > changes to the formating of the page.
    >
    > Help!
    >
    > http://www.thepurrfectnanny.com/map.php
    >
    > Code block that errors is:
    >
    > //Map Change function
    > function changeMap(){
    > //user_input = "kennesaw";
    > user_input = "";
    > for (i=0;i<document.forms[0].c1.length;i++) {
    > if (document.forms[0].c1.checked) {
    > user_input = document.forms[0].c1.value;
    > }
    > }
    > city = user_input;
    > onLoad(city);
    >
    > }


    Can you provide any hints as to the error you are seeing?
    Daz, Jan 18, 2007
    #2
    1. Advertising

  3. Darkstar 3D

    VK Guest

    Ref. Object doesn't support this property or method

    Because you were a very bad boy :) so you did not pre-declare
    user_input variable neither in global nor in local scope:
    var user_input;
    or
    var user_input = "something';

    Somewhere on your page you also have added an element with
    id="user_input". On IE (always) and on Gecko (in BackCompat mode) it
    leads to auto-created variable "user_input" referencing that element.
    Because you did not use var the system assumes that you are trying to
    assign empty string to that DOM element reference and this is indeed
    not allowed.
    VK, Jan 18, 2007
    #3
  4. Darkstar 3D

    Daz Guest

    VK wrote:

    > Ref. Object doesn't support this property or method
    >
    > Because you were a very bad boy :) so you did not pre-declare
    > user_input variable neither in global nor in local scope:
    > var user_input;
    > or
    > var user_input = "something';
    >
    > Somewhere on your page you also have added an element with
    > id="user_input". On IE (always) and on Gecko (in BackCompat mode) it
    > leads to auto-created variable "user_input" referencing that element.
    > Because you did not use var the system assumes that you are trying to
    > assign empty string to that DOM element reference and this is indeed
    > not allowed.


    It's good practise to always use 'var' when declaring variables, unless
    you have a specific reason not to. 'var' will make the variable private
    to the scope it's in, and it should therefore save a lot of coding
    problems, such as the one you experienced. I can't believe I didn't
    spot it. Nice site by the way. :)

    Daz.
    Daz, Jan 18, 2007
    #4
  5. Darkstar 3D

    Darkstar 3D Guest

    VK wrote:
    > Ref. Object doesn't support this property or method
    >
    > Because you were a very bad boy :) so you did not pre-declare
    > user_input variable neither in global nor in local scope:
    > var user_input;
    > or
    > var user_input = "something';
    >
    > Somewhere on your page you also have added an element with
    > id="user_input". On IE (always) and on Gecko (in BackCompat mode) it
    > leads to auto-created variable "user_input" referencing that element.
    > Because you did not use var the system assumes that you are trying to
    > assign empty string to that DOM element reference and this is indeed
    > not allowed.


    Wow! I must have blinders on. :) Think I was too focused on the
    conversion or something.

    Mucho thanks! Great explanation too as I learned a bit as well.
    Darkstar 3D, Jan 19, 2007
    #5
  6. Darkstar 3D

    Darkstar 3D Guest

    Daz wrote:
    > It's good practise to always use 'var' when declaring variables, unless
    > you have a specific reason not to. 'var' will make the variable private
    > to the scope it's in, and it should therefore save a lot of coding


    I do try, still fuming that I missed some. Although, I must admit that
    I don't do webpages for a living, but this client was the wife! :)

    > Nice site by the way. :)


    Thanks!
    Darkstar 3D, Jan 19, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. todd
    Replies:
    3
    Views:
    5,795
  2. Roman
    Replies:
    0
    Views:
    4,021
    Roman
    Jan 4, 2004
  3. zdrakec
    Replies:
    0
    Views:
    549
    zdrakec
    Sep 26, 2007
  4. Joe
    Replies:
    3
    Views:
    546
  5. JohnE
    Replies:
    1
    Views:
    1,032
    JohnE
    Mar 9, 2010
Loading...

Share This Page