Checkbox is not checked

-1

I have an application where a table is loaded dynamically via ajax, and inside the table there is a condition, if the condition is true I have to load a checkbox next to each name that is loaded, but when I load my application and I try to choose one of the checkboxes, checkbox does not stay checked

CALL AJAX

$.ajax({
    type: "POST",
    url:"inserir_sc_ajax.php",
    data:dados,
    success: function(result){
        if(result.length > 2){
            $("#fluxo").html('');
            $("#fluxo").append(result);
        }else{
            var option = "<option value='' >Nao Existe Fluxo para Este Grupo</option>";
            $("#fluxo").html('');
            $("#fluxo").append(option);
        }
    }
});

CODE

while ($ln2 = mysql_fetch_array($query)) {
    if($ln2['codNIvel'] == 2){
        echo "<tr>";
            echo "<td> <input type='checkbox' checked name='codRequestManager' value='{$ln2['codUser']}' /> ". $ln2['nome'] ." </td>";
        echo "</tr>";
    }else{  
        echo "<tr>";
            echo "<td> ". $ln2['nome'] ." </td>";
        echo "</tr>";
    }
}
    
asked by anonymous 27.08.2014 / 21:36

2 answers

1

I could ... the table I was talking about was loaded according to a select > < / select> strong>

$(document).change("#fluxo", function(){...}

All I did was put inside ready and it worked, it looked like this:

$(document).ready(function(){
   $("#fluxo").change(function(){...}
});

Now the reason it does not work the first way I do not know, but it's worth everyone for the help!

    
27.08.2014 / 22:51
0

Tried to specify the data type in ajax? Type dataType: 'html'

In PHP code I would put everything in a variable and return it in JSON format.

So:

   $retorno['html'] = array(); 
   while ($ln2 = mysql_fetch_array($query)) {
    if($ln2['codNIvel'] == 2){
        $retorno['html'] .= "<tr>";
            $retorno['html'] .= "<td> <input type='checkbox' checked name='codRequestManager' value='{$ln2['codUser']}' /> ". $ln2['nome'] ." </td>";
        $retorno['html'] .= "</tr>";
    }else{  
        $retorno['html'] .= "<tr>";
            $retorno['html'] .= "<td> ". $ln2['nome'] ." </td>";
        $retorno['html'] .= "</tr>";
    }
}
echo json_encode($retorno);

There in the ajax script would look like this:

$("#fluxo").append(result.html);
    
27.08.2014 / 22:03