Event ID issue

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Event ID issue

Mike Porter
Hi,
I am having troubles getting the ID attribute of a TR element... All
element types I think.
I am sure it is due to a misunderstanding on my part w/regard to
events... but I am at a loss.

I want to simple get the ID attribute from the object I attached an
event handler to. You see here that I have attached a sayHi handler to
all the TRs in a Table... In Firefox i do get the corrrect id in the
alert box...
However in IE I am getting 'undefined'.  Like I mentioned, Im sure it
has something to do w/ how im using the event.currentTarget.... whats
the best way to get the event from the real source TR in this case?

The TRs look something like this
<tr id="lens_row_1" class="caseRow" >

    var lens = {
        init: function(event){
            var rows =
document.getElementById('caseResults').getElementsByTagName("tr");
            for(i = 0; i < rows.length; i++){
                dojo.event.connect(rows[i], "onclick",lens, "sayHi");
            }
            },
        sayHi: function(event){
             var elemId = event.currentTarget.getAttribute('id');
              alert('hi' + elemId);
            },
}

Thanks in advance,

Mike
_______________________________________________
Dojo-interest mailing list
[hidden email]
http://dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Event ID issue

David Schontzler
Try event.target.id.

On 12/7/05, Mike Porter <[hidden email]> wrote:

> Hi,
> I am having troubles getting the ID attribute of a TR element... All
> element types I think.
> I am sure it is due to a misunderstanding on my part w/regard to
> events... but I am at a loss.
>
> I want to simple get the ID attribute from the object I attached an
> event handler to. You see here that I have attached a sayHi handler to
> all the TRs in a Table... In Firefox i do get the corrrect id in the
> alert box...
> However in IE I am getting 'undefined'.  Like I mentioned, Im sure it
> has something to do w/ how im using the event.currentTarget.... whats
> the best way to get the event from the real source TR in this case?
>
> The TRs look something like this
> <tr id="lens_row_1" class="caseRow" >
>
>     var lens = {
>         init: function(event){
>             var rows =
> document.getElementById('caseResults').getElementsByTagName("tr");
>             for(i = 0; i < rows.length; i++){
>                 dojo.event.connect(rows[i], "onclick",lens, "sayHi");
>             }
>             },
>         sayHi: function(event){
>              var elemId = event.currentTarget.getAttribute('id');
>               alert('hi' + elemId);
>             },
> }
>
> Thanks in advance,
>
> Mike
> _______________________________________________
> Dojo-interest mailing list
> [hidden email]
> http://dojotoolkit.org/mailman/listinfo/dojo-interest
>
_______________________________________________
Dojo-interest mailing list
[hidden email]
http://dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Event ID issue

Bill Keese-2
I wouldn't be surprised if IE and Firefox have a difference of behavior
with events on <tr>.  (I noticed a similar difference with the <button>
tag.)  You may have to hack around it.  (dojo.html.overElement() or
dojo.dom.isDescendantOf() may be useful)

Also, you may want to use dojo.html.getEventTarget() rather than
accessing the target directly.

(But hopefully, what David suggested will work)

David Schontzler wrote:

> Try event.target.id.
>
> On 12/7/05, Mike Porter <[hidden email]> wrote:
>  
>> Hi,
>> I am having troubles getting the ID attribute of a TR element... All
>> element types I think.
>> I am sure it is due to a misunderstanding on my part w/regard to
>> events... but I am at a loss.
>>
>> I want to simple get the ID attribute from the object I attached an
>> event handler to. You see here that I have attached a sayHi handler to
>> all the TRs in a Table... In Firefox i do get the corrrect id in the
>> alert box...
>> However in IE I am getting 'undefined'.  Like I mentioned, Im sure it
>> has something to do w/ how im using the event.currentTarget.... whats
>> the best way to get the event from the real source TR in this case?
>>
>> The TRs look something like this
>> <tr id="lens_row_1" class="caseRow" >
>>
>>     var lens = {
>>         init: function(event){
>>             var rows =
>> document.getElementById('caseResults').getElementsByTagName("tr");
>>             for(i = 0; i < rows.length; i++){
>>                 dojo.event.connect(rows[i], "onclick",lens, "sayHi");
>>             }
>>             },
>>         sayHi: function(event){
>>              var elemId = event.currentTarget.getAttribute('id');
>>               alert('hi' + elemId);
>>             },
>> }
>>
>> Thanks in advance,
>>
>> Mike
>> _______________________________________________
>> Dojo-interest mailing list
>> [hidden email]
>> http://dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>>    
> _______________________________________________
> Dojo-interest mailing list
> [hidden email]
> http://dojotoolkit.org/mailman/listinfo/dojo-interest
>  

_______________________________________________
Dojo-interest mailing list
[hidden email]
http://dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Event ID issue

Brad Neuberg
How is dojo.html.getEventTarget() different from using the target property of the event object passed in by the dojo.event system?

Brad

Bill Keese <[hidden email]> wrote:
I wouldn't be surprised if IE and Firefox have a difference of behavior
with events on . (I noticed a similar difference with the


_______________________________________________
Dojo-interest mailing list
[hidden email]
http://dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: Event ID issue

Alex Russell
On Wednesday 07 December 2005 5:50 pm, Brad Neuberg wrote:
> How is dojo.html.getEventTarget() different from  using the target
> property of the event object passed in by the  dojo.event system?

it's not, and getEventTarget shouldn't be necessaray if you're using
dojo.event.connect()

Regards

--
Alex Russell
[hidden email] BE03 E88D EABB 2116 CC49 8259 CF78 E242 59C3 9723
[hidden email]  F687 1964 1EF6 453E 9BD0 5148 A15D 1D43 AB92 9A46
_______________________________________________
Dojo-interest mailing list
[hidden email]
http://dojotoolkit.org/mailman/listinfo/dojo-interest