attachEvent XML toolbar

Am trying to attach an event to a button on my toolbar which is loaded from xml the problem is the function run no matter what button i press i can’t appear to attach it to just one element of the bar. could some please give me some advice

Toolbar sending button id to the event handler.

For example you have the following xml:

<?xml version="1.0"?>

    <item id=“new” type=“button” img=“new.gif”/>
    <item id=“save” type=“button” img=“save.gif”/>
    <item id=“open” type=“button” img=“open.gif”/>

Then attach an event to the toolbar:

toolbar.attachEvent(“onClick”, function(id){
    if (id == “new”) {
        // button new was pressed
    if (id == “save”) {

        // button save was pressed


    if (id == “open”) {

        // button open was pressed