views:

42

answers:

1
var ButtonFarmAtivada = new Array();

function X() {
var tableCol = dom.cn("td"); //cell 0

//create start checkbox button

ButtonFarmAtivada[index] = createInputButton("checkbox", index);

ButtonFarmAtivada[index].name = "buttonFarmAtivada_"+index;

ButtonFarmAtivada[index].checked = GM_getValue("farmAtivada_"+index, true);

FM_log(3,"checkboxFarm "+(index)+" = "+GM_getValue("farmAtivada_"+index));

ButtonFarmAtivada[index].addEventListener("click", function() {
       rp_farmAtivada(index);
}, false);

tableCol.appendChild(ButtonFarmAtivada[i]);

tableRow.appendChild(tableCol); // add the cell

}

1) is it possible to create the button inside an array as I'm trying to do in that example? like an array of buttons?

2) I ask that because I will have to change this button later from another function, and I'm trying to do that like this (not working):

function rp_marcadesmarcaFarm(valor) {

  var vListID = getAllVillageId().toString();

  FM_log(4,"MarcaDesmarcaFarm + vListID="+vListID);

  var attackList = vListID.split(",");

     for (i = 0; i <= attackList.length; i++) {
         FM_log(3, "Marca/desmarca = "+i+" "+buttonFarmAtivada[i].Checked);
         ButtonFarmAtivada[i].Checked = valor;
     };
};
A: 

For number 1) yes, you can.

function createInputButton(type, index) { // um, why the 'index' param?
    // also, why is this function called 'createInputButton'
    // if sometimes it returns a checkbox as opposed to a button?
    var inputButton = document.createElement("input");
    inputButton.type = type; // alternately you could use setAttribute like so:
                             // inputButton.setAttribute("type", type);
                             // it would be more XHTML-ish, ♪ if that's what you're into ♫
    return inputButton;
}

I don't really understand part 2, sorry.

LeguRi
2) How can I access that button from another function, for exemple, if I want to check if a button created with your function is "checked" (inputButton.Checked) ??
Fernando SBS
I suspect your issue is a case sensitivity issue; try changing `ButtonFarmAtivada[i].Checked` to `ButtonFarmAtivada[i].checked`
LeguRi