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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Web and WebWorks Development

Reply
New Developer
smorton
Posts: 7
Registered: ‎05-26-2009
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
Please use plain text.
Developer
Posts: 107
Registered: ‎09-25-2008

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?
Please use plain text.
New Developer
smorton
Posts: 7
Registered: ‎05-26-2009

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?

Please use plain text.
Developer
abarber
Posts: 189
Registered: ‎08-13-2008

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

 

 

Please use plain text.
New Developer
smorton
Posts: 7
Registered: ‎05-26-2009

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.
Please use plain text.
Developer
Posts: 107
Registered: ‎09-25-2008

Re: Event.currentTarget - empty?

I tried onchange="foo(event.currentTarget.id)" and that worked fine (note the lowercase 'e' in event).
Please use plain text.
New Developer
smorton
Posts: 7
Registered: ‎05-26-2009

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

Please use plain text.