SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I am having problems with javascript OOP

    Whenever I try to create an object in javascript and give one of its variables the value of an object like this:

    function theObj(obj_id) {
    this.obj=document.getElementById(obj_id);
    }

    It gives me an error message. I dont have the slightest clue as to why this is. Please help me with this problem.
    Last edited by joekarbakuitz; Mar 21, 2002 at 05:01.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Birmingham, UK
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it could be because when you have a function with a variable within the brackets (function theObj(obj_id) { ) it means its gettin a value to put in the place of obj_id from another part of the source code.

  3. #3
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure that you don't run the code until the page has finished loading, or at least wait until all the layers you would access are finished loading. If that doesn't help post some more code.
    ck :: bringing chris to the masses.

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alert the obj_id to see what it's giving you.

    If it says [object] then you already have the dom handle reference.

    Otherwise it'll give you a name which you can check is actually an object in the page.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if think it was this

    "If it says [object] then you already have the dom handle reference."

    do you mean if you call the function from say 'onlick' it passes that id to the function?

  6. #6
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would have the [object] handle if the function caller was passed a document.element handle:

    handlemefunction(document.field);

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It turned out to be where I was assigning the object to that variable before the page was fully loaded.

    Thanks for your help!


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
  •