Checkbox is not checked

Asked

Viewed 377 times

-1

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

CALLED 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>";
    }
}
  • Already tried checked='checked' or checked=true ?

  • already yes... in the code is actually not to have the "checked", I put as test and forgot to take

  • You can better explain what you want. You want to have the checkbox selected by default?

  • when my table appears, if the lines fall in condition, the checkbox will appear (unchecked), then I will click on one of them to then do another action...only that the checkbox is not marked when I click on any of them

  • I only sell all the code, including css. It may be that there is some other element, for example, above the checkbox, or you have some disabled = true lost in the code.

2 answers

1

I got... the table I was talking about was loaded according to a < select >< /select > only that I called the change as follows outside the ready

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

All I did was put inside the ready and it worked, it was as follows:

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

Now the reason why it doesn’t work the first way I don’t know, but Valew to all for help !

0

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

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

Thus:

   $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);

Then in the ajax script it would look like this:

$("#fluxo").append(result.html);
  • I’ll try, as soon as I’m done I give my answer whether it worked or not !

Browser other questions tagged

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