SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
-
Mar 21, 2002, 04:54 #1
- 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.
-
Mar 21, 2002, 07:14 #2
- 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.
-
Mar 21, 2002, 09:30 #3
- 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.
-
Mar 21, 2002, 10:16 #4
- 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 |=---
-
Mar 21, 2002, 11:03 #5
- 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?
-
Mar 21, 2002, 11:16 #6
- 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 |=---
-
Mar 21, 2002, 17:22 #7
- 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