PDA

Click to See Complete Forum and Search --> : Anonymous References


CiberTHuG
Mar 28th, 2001, 02:36 PM
Okay... I have a series of document objects


<table>
<tr id='objRow'></tr>
<tr id='objRow'></tr>
<tr id='objRow'></tr>
<tr id='objAnotherRow'></tr>
<tr id='objAnotherRow'></tr>
<tr id='objAnotherRow'></tr>
<tr id='objDifferentRow'></tr>
<tr id='objDifferentRow'></tr>
<tr id='objDifferentRow'></tr>
</table>


I have some onClick events that pass the name of one of these objects. Let's say I want to make them hide.


<script language=JavaScript>
function hide(x) {
for (var i = 0; i < x.length; i++) {
x\[i\].style.display = "none";
}
}
</script>


Well, it is looking for an object called x. I want to anonymously refer to the object, using x. How can I do this?

sail3005
Mar 28th, 2001, 06:59 PM
ok, i am not sure if this is what you want, but here goes:

when you have the onclick, you can tell the function what called it by sending it "this".

for example:


onClick="whateverFunction(this)"


I hope this helps.

CiberTHuG
Mar 29th, 2001, 10:01 AM
Well...

I have this, perhaps this is wrong.


<a href='javascript:void()' id='objRow' onclick='ToggleDisplay(this)'>Click Me!</a>


I used to not have an id on that, just having the name objRow as the ToggleDisplay() param. But with the above, I'm getting javascript:void() in the function.

Anyway, I bought the Rhino book last night. I'll see what I can learn.

CiberTHuG
Mar 29th, 2001, 10:20 AM
I got it to work. For the longest time I was using quotes in the function call, thinking I had to pass the name of the rows to be affected. I wanted a way to get at x's value, not use x. When I left out the quotes it passed a reference to the object with that name. x was now a reference to the rows to be affected.

It was a very very very simple problem.