0

I have many checkbox with onchange event that change line color where is checked :

<input type="checkbox" onchange="cocheCommande($(this))" name="${NAME_SELECTION}" value="<%=command.getCdeId()%>"  />

function cocheCommande(chk)
{
    alert("test cocheCommande");
    var tr=chk.closest('tr');

    if (chk.is(':checked'))
    {
        tr.css('background','#33EE33');
        tr.nextUntil("tr.entete","tr").css('background','#FFFF33');
    }
    else
    {
        tr.css('background','#D0EED0');
        tr.nextUntil("tr.entete","tr").css('background','#EEEED0');
    }
}

I have a function that allows to check everything or uncheck. But if I use, onchange event is never call even though everything is checked. Why ? And how can I do ?

Grichka
  • 53
  • 1
  • 11

1 Answers1

0

As others said, you can't use $ in the html template; you can, however, pass this as the argument to your onchange handler:

HTML:

<input onchange="change(this)" type="checkbox" />

JS:

function change(elem) {
  var element = $(elem);
  console.log(element.next())
}

https://plnkr.co/edit/dx8GoJxHwKa52VFCkn2G?p=preview

Fissio
  • 3,748
  • 16
  • 31
  • Ok, it works when I check one by one (like before) but when I check everything at the same time with a function, onchange is never call... – Grichka Dec 07 '16 at 14:52
  • Well, that's another problem :) You should probably change your "select all" function somehow then – Fissio Dec 07 '16 at 14:59