How to store references to objects in an array

Hi
My aim is to have an array as a property of an object, in which references to html objects are stored.
Here is a sample code of what I mean:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script>
obj = {}
obj.div = document.getElementById("mydiv")
function one(){
      document.getElementById("mydiv").style.visibility="hidden"
}
function two(){
      obj.div.style.visibility="hidden"
}
</script>
<body>
<div id="mydiv">abcde</div>
<a href="javascript:void(0)" onClick="one()">One</a>
<a href="javascript:void(0)" onClick="two()">Two</a>
</body>
</html>

The "one" link works, but the "two" link fails giving "object exptected" error. typeof(obj.div) gives me null, while I want this to give me object.
Am I misunderstanding any thing here?
Huji
LVL 14
hujiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

archrajanCommented:
u have just one div and that works when u call that...
and when the function executes its style is set to hidden and there is nothing available for the second one to execute
0
archrajanCommented:
can u give a more clear explanation of what u r trying to do here please
0
archrajanCommented:
check this
<span id="blah"></span>
<span id="blah2"></span>
<script>
var names = new array("blah", "blah2");
var values = new array("test", "test2");
var fields = new array("innerHTML", "innerHTML");
document.getElementById(names[0])[fields[0]] = values[0];
</script>

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

archrajanCommented:
also check this forum post here http://www.webmasterworld.com/forum91/2394.htm
0
hujiAuthor Commented:
Again: When you click on the link "one" it works, as it should. But when you click on link "two" it fails.
I want test.div to work just as document.getElementById("mydiv")
0
GwynforWebCommented:
At the tim eof assign the div has not been parsed so it does not exist, putting the script after the div (or calling off the onload) will solve this

<body>
<div id="mydiv">
<p>abcde</p>
</div><a href="javascript:void(0)" onClick="one()">

<p>One</a> <a href="javascript:void(0)" onClick="two()">Two</a> <script>
obj = {}
obj.div = document.getElementById("mydiv")
function one(){
     document.getElementById("mydiv").style.visibility="hidden"
}
function two(){
     obj.div.style.visibility="hidden"
}
</script>
</body>

0
archrajanCommented:

document.getElementById(ids[a])[fields[b]] = values[c]
0
GwynforWebCommented:
shld read
 " At the time of assignment  the div.."
0
GwynforWebCommented:
sorry my indentation was terrible, more tidy

<body>
 <div id="mydiv">
  <p>abcde</p>
 </div>
  <a href="javascript:void(0)" onClick="one()"><p>One</a>
  <a href="javascript:void(0)" onClick="two()">Two</a>

<script>
 obj = {}
 obj.div = document.getElementById("mydiv")
 function one(){
     document.getElementById("mydiv").style.visibility="hidden"
 }
 function two(){
     obj.div.style.visibility="hidden"
 }
</script>
</body>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.