Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery how to get array from checked checkboxes
    primarykey
    data
    text
    <p>I need to pass data as an array to a fancybox instance in JQuery.</p> <p>The passed format needs to look like this: <code>Array( [remove] =&gt; Array ( [1] =&gt; 1 [109] =&gt; 109 [110] =&gt; 110 ))</code></p> <p>Now I use the following code, but this doesn't work because I'm not passing an array.</p> <p>Thanks in advance...</p> <p>Checkboxes look like this and are generated on the database results:</p> <pre><code>&lt;td class="checkboxTable"&gt;&lt;input name="remove[&lt;?php echo $users-&gt;id; ?&gt;]" type="checkbox" id="checkbox[]" value="&lt;?php echo $users-&gt;id; ?&gt;"/&gt;&lt;/td&gt; </code></pre> <p>The javascript I use is this:</p> <pre><code>$('.deleteConfirmationMultiple').Loader({ url: ['/dgpcms/public/fancybox/jquery.fancybox-1.3.2.pack.js', '/dgpcms/public/fancybox/jquery.easing-1.3.pack.js', '/dgpcms/public/fancybox/jquery.mousewheel-3.0.4.pack.js', '/dgpcms/public/fancybox/jquery.fancybox-1.3.2.css'], ////debug: [true], cache: [true], success: function(target){ $(this).fancybox({ 'autoDimensions' : true, 'autoScale' : true, 'overlayOpacity' : '0.70', 'overlayColor' : '#000000', 'transitionIn' : 'none', 'transitionOut' : 'none', 'hideOnOverlayClick': false, 'hideOnContentClick': false, 'showCloseButton' : false, 'href' : $('#deleteConfirmation').attr('action'), ajax : { type : 'POST', data : $('input:checkbox:checked') } }); } }); </code></pre> <p>Is there a way to pass the values exactly as PHP would do it (like this: <code>Array ( [remove] =&gt; Array ( [1] =&gt; 1 [109] =&gt; 109 [110] =&gt; 110 ) [deleteMultiple] =&gt; Delete selected )</code>)?</p> <p><strong>EDIT 12 Jan 2011</strong></p> <p>I got a bit further, but nof there is a weird problem..</p> <p>Id isn't posted as data in my ajax call. When I create an onclick function for the checkall link (all checkboxes get selected) and call the getData function and alert the result, I get the id's of the checked boxes. But calling the function in my ajax call returns empty...</p> <p>Here is the code:</p> <pre><code>$('.deleteConfirmationMultiple').Loader({ url: ['/dgpcms/public/fancybox/jquery.fancybox-1.3.2.pack.js', '/dgpcms/public/fancybox/jquery.easing-1.3.pack.js', '/dgpcms/public/fancybox/jquery.mousewheel-3.0.4.pack.js', '/dgpcms/public/fancybox/jquery.fancybox-1.3.2.css'], ////debug: [true], cache: [true], success: function(target){ // Array( [remove] =&gt; Array ( [1] =&gt; 1 [109] =&gt; 109 [110] =&gt; 110 )) // var id = {5: '5', 6: '6', 7: '7'}; var id = ''; $.fn.getData = function(options){ var id = $('input:checkbox:checked').map(function(){ return this.value.serialize(); }).get(); //alert(id); return id; }; $(this).fancybox({ 'autoDimensions' : true, 'autoScale' : true, 'overlayOpacity' : '0.70', 'overlayColor' : '#000000', 'transitionIn' : 'none', 'transitionOut' : 'none', 'hideOnOverlayClick': false, 'hideOnContentClick': false, 'showCloseButton' : false, 'href' : $('#deleteConfirmation').attr('action'), ajax : { type : 'POST', data : {'remove':id} } }); } }); </code></pre> <p><strong>Edit 12 Jan 2010</strong></p> <p>The code below, containing an array hardcoded works precisely as I want, Now I need to create the same thing from the checked checkboxes....</p> <pre><code>var id = {5: '5', 6: '6', 7: '7'}; $(this).fancybox({ 'autoDimensions' : true, 'autoScale' : true, 'overlayOpacity' : '0.70', 'overlayColor' : '#000000', 'transitionIn' : 'none', 'transitionOut' : 'none', 'hideOnOverlayClick': false, 'hideOnContentClick': false, 'showCloseButton' : false, 'href' : $('#deleteConfirmation').attr('action'), ajax : { type : 'POST', data : {'remove':id} } }); </code></pre>
    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