Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery set checkbox checked
    primarykey
    data
    text
    <p>I already tried all the possible ways, but I still didn't get it working. I have a modal window with a <code>checkbox</code> I want that when the modal opens, the <code>checkbox</code> check or uncheck should be based on a database value. (I have that already working with others form fields.) I started trying to get it checked but it didn't work.</p> <p>My html div:</p> <pre><code>&lt;div id="fModal" class="modal" &gt; ... &lt;div class="row-form"&gt; &lt;div class="span12"&gt; &lt;span class="top title"&gt;Estado&lt;/span&gt; &lt;input type="checkbox" id="estado_cat" class="ibtn"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>and the jquery:</p> <pre><code>$("#estado_cat").prop( "checked", true ); </code></pre> <p>I also tried with <code>attr</code>, and others seen here in the forums, but none seem to work. Can someone point me the right way?</p> <p>EDIT: ok, I'm really missing something here... I can check/uncheck using code if the check box is in the page, but is it's in the modal window, I can't. I tried dozens of different ways...</p> <p>I have a link that's supposed to open the modal: </p> <p>and jquery to "listen" the click and execute some operations like filling some text boxes with data coming from database. Everything works like I want but the problem is that I can't set checkbox checked/unchecked using code. help please!</p> <pre><code>$(function() { $(".editButton").click(function(){ var id = $(this).data('id'); $.ajax({ type: "POST", url: "process.php", dataType:"json", data: { id: id, op: "edit" }, }).done(function( data ) { //the next two lines work fine, i.e., it grabs the value from database and fills the textboxes $("#nome_categoria").val( data['nome_categoria'] ); $("#descricao_categoria").val( data['descricao_categoria'] ); //then I tried to set the checkbox checked (because its unchecked by default) and it does not work $("#estado_cat").prop("checked", true); $('#fModal').modal('show'); }); evt.preventDefault(); return false; }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload