PDA

View Full Version : add events to dynamic items


whatknows
12-07-2003, 05:08 AM
Hello all!

Been working on this for a while, and I am pretty frustrated. I am trying to set up event actions and I am lost. I have dynamically created some radio buttons, and when one is click, I want the function submitCode called. Something is wrong but I can't figure out what. Here is the code:

function submitCode(data) {
trace(data);
}

for (i = 1; i<=6; i++) {
panel.createObject("RadioButton", "option" + i, i);
option = eval("panel.option" + i);
option.data = i;
option.groupName = "option"

option.addEventListener("click", submitCode(this.data));
}

For some reason, it is actually running the function each time through the loop, rather than waiting for the click. I could be doing this whole thing wrong, but as I said, I am lost. Any help would be great!

Thanks in advance!