How to store previously checked Checkboxes values?

Asked

Viewed 44 times

1

Hello. I’m making a system that allows access to folders. I search the folder, which has its id and permissions saved in the database, select it, loading its subfolder and checkboxes are loaded to determine the permissions that users will have to them. Only, when searching for another folder, this, previously selected, will disappear from the page. I would like to save the values set in the checkboxes.

Function assembling folder list and permissions checkboxes:

function monta_arvore(a){
          $.each(a.pastasFilhas, function(){
            $("#trazPastas").append("<tr id='pasta"+$(this)[0].id+"'><td id='temFilho"+$(this)[0].id+"'><td style='padding-left:"+$(this)[0][0].margem_esq+"'><input id=checkTds"+$(this)[0].id+" onchange=checarTdsPerm("+$(this)[0].id+") type='checkbox'>"+$(this)[0].id+" "+$(this)[0].nome+"</td></td><td style='left:0'><TD WIDTH='17' ALIGN='CENTER'><input type='checkbox' pastaChecada = "+$(this)[0].id+" id=pasta_ver-"+$(this)[0].id+" class='checarTudo'></TD><TD WIDTH='17' ALIGN='CENTER'><input type='checkbox' pastaChecada = "+$(this)[0].id+" id='pasta_criar-"+$(this)[0].id+"' class='checarTudo'></TD><TD WIDTH='17' ALIGN='CENTER'><input type='checkbox' pastaChecada = "+$(this)[0].id+" id='pasta_excluir-"+$(this)[0].id+"' class='checarTudo'></TD><TD WIDTH='17' ALIGN='CENTER'><input type='checkbox' pastaChecada = "+$(this)[0].id+" id='pasta_renomear-"+$(this)[0].id+"' class='checarTudo'></TD><TD WIDTH='17' ALIGN='CENTER'><input type='checkbox' pastaChecada = "+$(this)[0].id+" id='pasta_mover-"+$(this)[0].id+"' class='checarTudo'></TD><TD WIDTH='17' ALIGN='CENTER'><input type='checkbox' pastaChecada = "+$(this)[0].id+" id='arquivo_criar-"+$(this)[0].id+"' class='checarTudo'></TD><TD WIDTH='17' ALIGN='CENTER'><input type='checkbox' pastaChecada = "+$(this)[0].id+" id='arquivo_excluir-"+$(this)[0].id+"' class='checarTudo'></TD><TD WIDTH='17' ALIGN='CENTER'><input type='checkbox' pastaChecada = "+$(this)[0].id+" id='arquivo_renomear-"+$(this)[0].id+"' class='checarTudo'></TD><TD WIDTH='17' ALIGN='CENTER'><input type='checkbox' pastaChecada = "+$(this)[0].id+" id='arquivo_mover-"+$(this)[0].id+"' class='checarTudo'></TD><td></tr>");
            if($(this)[0].filhos){
              $("#checkTds"+$(this)[0].id).after("<td style='display:inline-block;'><div><a href='javascript:geraFilho("+$(this)[0].id+","+$(this)[0][0].margem_esq+17+")'><img id='mais"+$(this)[0].id+"' src='../imagens/icon-arrow-down-b-16.png' alt='+' height='14px' width='10px'></a></td>");
            }
          });

        }

Function that reads checkboxes:

function testeLeituraPermissões(){
var i=0;
var objetoPermissoesPastas = function(){};

var objPermissoesPastas = new objetoPermissoesPastas();

$.each($(".checarTudo"), function(){
  objPermissoesPastas[$(this)[0].id] = 0
  i++;
});

var permissoes = [];

$.each($(".checarTudo:checked"), function(){
    objPermissoesPastas[$(this)[0].id] = 1;
});
}

I wonder if you have how to save, if it can be saved in session, the folder id and permissions?

Thank you.

  • Changes all the $(this)[0] for this you’re encapsulating needlessly.

  • You are switching pages or just loading new content that overwrites checkboxes?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.