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
Trusted Contributor
mobilvar
Posts: 119
Registered: ‎11-28-2011
My Device: 9930
Accepted Solution

Adding Event to Link Doesn't Work

In Javascript I am using a function ( I'll call it "function1" ) to create an unordered list.

In the script that creates the unordered list, I am trying to modify the onClick property of each item so that when an item in the list is clicked, another  function ( I'll call it "function2") is called and that function passes the item's ID as a parameter. I think this should work, but I can't seem  to get the ID passed to my function. 

 

Here is the script used by function1 to set the properties for the unordered list:

 return '<ul><a class="states"  onClick = "function2(this);" ID = "' + row.id + '" href="#" >' + row.state_primary + '</a></ul>';

 

Here is the script for function2:

function populate_state_station_programs(station_state) {
alert (station_state.ID);

}

 

My alert in function2 keeps displaying "Undefined" instead of the ID value I want to capture.

I hope my explanation is clear. Can someone give me some feedback on what may be going wrong?

Please use plain text.
Trusted Contributor
mobilvar
Posts: 119
Registered: ‎11-28-2011
My Device: 9930

Re: Adding Event to Link Doesn't Work

Sorry, gang.

I wasn't setting the id property for the anchor properly. In my example below, row.id actually had no value.

When I set it properly, I got the expected alert in the click event.

Please use plain text.