Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Highlighted
New Developer
Posts: 7
Registered: ‎05-26-2009
My Device: Not Specified
Accepted Solution

Event.currentTarget - empty?

[ Edited ]

Currently researching Blackberry Browser software solution and have found an issue.  I am creating a html input text via asp.net and attach an onchange event to the list.  Upon onchange I simply want to display the id of the text box that generated fired the onchange

 

Attempts made....

 

alert(Event.currentTarget); = empty alert

 

alert(Event.currentTarget.id);= no alert.  I assume an exception is thrown behind the scence.

 

Anyone from RIM care to comment?  How can I get the id of the element that triggered the event?  The preferred method would be W3C compliant.

 

Thanks,

 

smorton

 

 

 

 

 

Message Edited by smorton on 05-26-2009 04:19 PM
Developer
Posts: 107
Registered: ‎09-25-2008
My Device: Not Specified

Re: Event.currentTarget - empty?

"Event.currentTarget" is not W3C-compliant. Something like "e.currentTarget" would be, if e were the event object passed to the event handler. What does your actual HTML look like?
New Developer
Posts: 7
Registered: ‎05-26-2009
My Device: Not Specified

Re: Event.currentTarget - empty?

Using an external js file this seems to work.  elementId is a global var in the js file.  

<input name="bla" type="text" id="bla" onchange="elementId=this.id;  someObject.method();" value="7.00" />

 

That being said I don't like this solution. I agree e.currentTarget would be the best approach e doesn't exist in the BB.  Am I missing something?

Developer
Posts: 189
Registered: ‎08-13-2008
My Device: Not Specified

Re: Event.currentTarget - empty?

Hello

 

I would pass the id in the method parameter.

onchange="someObject.method(this.id)"

 

I'm not sure that the event.currentTarget.id would work for a text box, I don't think this method works in IE.

 

Andrew

 

 

New Developer
Posts: 7
Registered: ‎05-26-2009
My Device: Not Specified

Re: Event.currentTarget - empty?

Tried that already.  Once in the method the reference to this is set to the current object and not the page.
Developer
Posts: 107
Registered: ‎09-25-2008
My Device: Not Specified

Re: Event.currentTarget - empty?

I tried onchange="foo(event.currentTarget.id)" and that worked fine (note the lowercase 'e' in event).
New Developer
Posts: 7
Registered: ‎05-26-2009
My Device: Not Specified

Re: Event.currentTarget - empty?

Excellent.  I thought I had tried that already but I think I had the event reference in my external js file which would have flawed the test.

 

Thanks