views:

59

answers:

2
function rp_marcadesmarcaFarm(valor) {

    FM_log(3, "marcadesmarcaFarm called = "+valor);

    for (i = 0; i < farmList.length; i++) {

        var arr        = farmList[i].split("|");
        var xy         = arr[0].split(",");
        var fvillageId = xy2id(parseInt(xy[0]), parseInt(xy[1]));

        GM_setValue("farmAtivada_"+suffixLocal+fvillageId, valor);
        GM_setValue("farmAtivada_"+suffixLocal+i, valor);
    };

    reloadFarmTable();
};

function createLinkButton(text, title, jsFunction, value) {   

  var button       = dom.cn("a");    
  button.href      = "javascript:void(0)";    
  button.innerHTML = text;    
  button.title     = title;

  if (jsFunction != null) {    
    button.addEventListener('click', jsFunction, false);    
  }

  return button;    
}

createLinkButton("X", T('CHECKFARM_M'), rp_marcadesmarcaFarm(true));

apparently the last argument (rp_marcadesmarcaFarm(true)) when invoking the createLinkButton is not working. If I change to:

createLinkButton("X", T('CHECKFARM_M'), rp_marcadesmarcaFarm);

it works. So how can I pass the (true) variable to the third argument of createLinkButton?

+5  A: 
createLinkButton("X", T('CHECKFARM_M'), function() {rp_marcadesmarcaFarm(true)});
Jakub Hampl
thank you, that did the trick!!
Fernando SBS
+1  A: 

createLinkButton is waiting for a function, but rp_marcadesmarcaFarm(true) calls the function and actually pass the return value.

What you want is an anonymous function that will call rp_marcadesmarcaFarm(true) and pass that to createLinkButton

createLinkButton("X", T('CHECKFARM_M'), function(){ rp_marcadesmarcaFarm(true); });
Vincent Robert
cause when I click the button it invoke that function which does stuff.
Fernando SBS