|
-
Jul 31st, 2001, 11:55 AM
#1
Thread Starter
Hyperactive Member
Javascript calling object
How can I get the name of the object calling a procedure through a DHTML event. So
that I can do the following:
CallingObject.style.left=XXX
At the moment I have a seperate procedure for each object.
TIA
-TiPaRa
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
-
Jul 31st, 2001, 08:10 PM
#2
Fanatic Member
Try:
event.srcElement.style.left=
-
Aug 1st, 2001, 06:44 AM
#3
Thread Starter
Hyperactive Member
Hmmm, It sort of works. How can I get the type of object it returns. I tried event.srcElement.type but it just returns [object].
I need it to return the name of a table when the top cell is clicked.
TIA again
-TiPeRa
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
-
Aug 1st, 2001, 09:14 AM
#4
Lively Member
You could do this (I'll show a possibility later), but I recommend you just alter the function definition to include an argument for the source of the event:
Code:
function foo(esource) {
alert('Source Element = ' + esource);
}
If your event is currently called like this:
Code:
Example 1:
<table>
<tr>
<td id='elt1' onclick="foo()">Something</td>
</tr>
<tr>
<td id='elt2' onclick="foo()">Something</td>
</tr>
</table>
Just alter the function calls to be:
Code:
Example 2:
<table>
<tr>
<td id='elt1' onclick="foo('elt1')">Something</td>
</tr>
<tr>
<td id='elt2' onclick="foo('elt2')">Something</td>
</tr>
</table>
The code above should work cross browser/platform
Or... (possibly IE version specific)
Assuming you have the code as in Example 1, alter your function to be:
Code:
function foo() {
alert('Source Element ID = ' + event.srcElement.id);
}
Is this what you wanted?
-
Aug 1st, 2001, 09:46 AM
#5
Thread Starter
Hyperactive Member
Sorted, (maybe) just one more thing. How do I get the parent of the object:
<table id="tbltest">
<tr>
<td id='tdtest' onclick="foo()">Something</td>
</tr>
</table>
In this situation I need to get the tbltest object when tdtest is clicked. I could probably find it somewhere on MSDN but you're a lot more help ful.
-TiPeRa
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
-
Aug 1st, 2001, 10:07 AM
#6
Lively Member
Surprisingly enough:
Code:
function foo() {
alert('Source Element ID = ' + event.srcElement.parentElement.id);
}
This will give the id of the TR element which contains the TD. Here is the really surprising bit...
Code:
function foo() {
alert('Source Element ID = ' + event.srcElement.parentElement.parentElement.parentElement.id);
}
This code gives the parent of the parent of the parent, which is the TABLE containing the TBODY containing the TR containing the TD
Cool??
-
Aug 1st, 2001, 02:11 PM
#7
Thread Starter
Hyperactive Member
Thanks a lot. It works great now.
-TiPeRa
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|