Firefox error obj.style has no properties

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danellison
    New Member
    • Apr 2007
    • 3

    Firefox error obj.style has no properties

    Greetings all. If only I was a little braver I would just shoot myself and end my misery but since I am not - please shoot me!!! I mean HELP me :)

    Picture a named form with contents defined as follows:

    [HTML]
    <form name="myform">
    <div id="extrawhatev er" style="visibili ty: 'hidden'> <!-- div and select do share -->
    <select name="extrawhat ever"> <!-- common name/id value -->
    <!-- options will be filled in dynamically later -->
    </select>
    </div>
    <input type="text" name="whatever" id="whatever" onfocus="prepmy List();">
    ...
    </form>
    [/HTML]

    As I understand things, if an form element has focus its container (form) MUST exist in the memory space right??? If I can use getElementById( 'whatever') on one line of code it should also work on the next line? So now the focus handler contains:

    Code:
    function prepmyList(arg) {
        var x = new getObj('extra'+arg); // ref hidden div from above by id so I can
       // make it visible after it is populated
        ...
    }
     
    function  getObj(arg) {
        this.obj = document.getElementById(arg);     // THIS WORKS FINE!!!!
        this.style = document.getElementById(arg).style;   // ERROR NO PROPERTIES
        ....
    }
    Note that IE6 and 7 run this just fine. Firefox is the complainer. I am trying to use Firebug to debug another area of my code that is after this point.

    This is driving me on the short trip to CRAZY. Anybody got a grip on it? Any ideas will be greatly appreciated.

    Impeach the whole government!
    Dan Ellison
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    try

    this.style = document.getEle mentById(arg).s tyle;

    to
    this.style = this.obj.style;


    and it may be something silly like firefox may not take .style as a whole but it prolly wants individual styles

    this.style.widt h = this.obj.style. width;

    Comment

    • danellison
      New Member
      • Apr 2007
      • 3

      #3
      Originally posted by iam_clint
      try

      this.style = document.getEle mentById(arg).s tyle;

      to
      this.style = this.obj.style;


      and it may be something silly like firefox may not take .style as a whole but it prolly wants individual styles

      this.style.widt h = this.obj.style. width;
      Thanks for the suggestions Clint. The first approach you are suggesting I don't think will work because the context of the object is such that a reference to "this" outside of the constructor will be an undefined object (or am I off track with that?)

      The way the objects are used is such that I don't think that the style attribute is a subset of obj....

      The later explanation is probably right on for firefox. It might be seeing this.style as an incomplete specification. This crossplatform stuff can be maddening! I do appreciate the assistance and I will see if I can make use of the suggestions.

      Thanks,
      Dan

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Code:
        function  getObj(arg) {
            this.obj = document.getElementById(arg);     // THIS WORKS FINE!!!!
            this.style = document.getElementById(arg).style;   // ERROR NO PROPERTIES
            ....
        }
        How about this, then:

        Code:
        function  getObj(arg) {
            var $theObj = document.getElementById(arg);
            this.obj = $theObj;
            this.style = $theObj.style;
            ....
        }

        Comment

        Working...