Note that there are some explanatory texts on larger screens.

plurals
  1. POSerialize a form which is generated by ajax, using jquery
    primarykey
    data
    text
    <p>I have a form with checkboxes and it is generated using ajax and jquery UI tabs. I am submitting the form with post when someone clicks on a button. It works for the first tab loaded with ajax, but clicking on other tabs and then trying to submit the form, the data from the form is empty. So the serialize function does not work after changing tabs because it thinks the form is empty. </p> <pre><code> // Bulk action Delegate $("body").delegate(".bulk_action_btn", "click", function(){ var data = $("#ActionAddForm").serialize(); var action = $(this).attr('title'); var currentTab = $( "#asst_tabs" ).tabs( "option", "selected" ); $('.asst_list2').fadeOut(); $.ajax({ type: "POST", url: "&lt;?php echo $html-&gt;url("/admin/actions/perform/") ?&gt;"+currentTab + '/' + action, data: data, cache: false, success: function(html){ $('.asst_list2').html(html); $('.asst_list2').fadeIn(100); // $("input[type=checkbox]").attr("checked",false); } }); }); </code></pre> <p>Here is the relative html markup, the actual markup is much longer.</p> <pre><code>&lt;div class="asst_action_bar"&gt; &lt;div class="action_group"&gt; &lt;p&gt;Bulk Actions&lt;/p&gt; &lt;input value="Follow" class="bulk_action_btn" title="Follow" type="button"&gt; &lt;input value="Unfollow" class="bulk_action_btn" title="Unfollow" type="button"&gt; &lt;/div&gt; &lt;form action="/admin/actions/add" method="post" id="ActionAddForm"&gt; &lt;fieldset style="display: none;"&gt;&lt;input type="hidden" value="POST" name="_method"&gt;&lt;/fieldset&gt; &lt;!-- Loaded with ajax --&gt; &lt;div class="input checkbox"&gt;&lt;input name="data[Assignment][1580]" id="Assignment1580_" value="0" type="hidden"&gt;&lt;input name="data[Assignment][1580]" value="1" id="Assignment1580" type="checkbox"&gt;&lt;/div&gt; &lt;div id="1580"&gt; &lt;p&gt;&lt;a href="javascript:" class="star"&gt;&lt;img src="/img/top/followmestar-on.gif" alt="" height="40" width="40"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class="input checkbox"&gt;&lt;input name="data[Assignment][1580]" id="Assignment1580_" value="0" type="hidden"&gt;&lt;input name="data[Assignment][1580]" value="1" id="Assignment1580" type="checkbox"&gt;&lt;/div&gt; &lt;div id="1580"&gt; &lt;p&gt;&lt;a href="javascript:" class="star"&gt;&lt;img src="/img/top/followmestar-on.gif" alt="" height="40" width="40"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class="input checkbox"&gt;&lt;input name="data[Assignment][1580]" id="Assignment1580_" value="0" type="hidden"&gt;&lt;input name="data[Assignment][1580]" value="1" id="Assignment1580" type="checkbox"&gt;&lt;/div&gt; &lt;div id="1580"&gt; &lt;p&gt;&lt;a href="javascript:" class="star"&gt;&lt;img src="/img/top/followmestar-on.gif" alt="" height="40" width="40"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;!-- Loaded with ajax end --&gt; &lt;/form&gt; </code></pre> <p></p> <p>I think the reason it doesn't work is that I am using the "#ActionAddForm" selector (the id of the form), which is probably not loaded after changing tabs. I am using cakePHP on the backend if that helps. I am using the jquery delegate method because it didn't work the form with the checkboxes is loaded with ajax.</p>
    singulars
    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.
    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