multi submit buttons multi checkboxes no form jquery ajax php submission

Bruce

I have 10 check boxes on a page. I have a "check all" button, works perfect.

I have 4 submit buttons - 2 to delete the records, and 2 to suspend the records.

The checkboxes are not contained by a form.

<button type="button" class="btn btn-small btn-warning tip suspend" data-original-title="Suspend"><span class="icon-minus icon-white"></span></button>
<button type="button" class="btn btn-small btn-danger tip delete" data-original-title="Delete"><span class="icon-remove icon-white"></span></button>

<input type="checkbox" class="checkbox" value="0" />
<input type="checkbox" class="checkbox" value="1" />
<input type="checkbox" class="checkbox" value="2" />
<input type="checkbox" class="checkbox" value="3" />
<input type="checkbox" class="checkbox" value="4" />
<input type="checkbox" class="checkbox" value="5" />
<input type="checkbox" class="checkbox" value="6" />
<input type="checkbox" class="checkbox" value="7" />
<input type="checkbox" class="checkbox" value="8" />
<input type="checkbox" class="checkbox" value="9" />

<button type="button" class="btn btn-small btn-warning tip suspend" 
data-original-title="Suspend"><span class="icon-minus icon-white"></span>
</button>

<button type="button" class="btn btn-small btn-danger tip delete" 
data-original-title="Delete"><span class="icon-remove icon-white"></span>
</button>

When a delete button is clicked, I need to send all checked boxes via ajax to a delete_record.php

When a suspend button is clicked, I need to send all checked boxes via ajax to a suspend_record.php

I know I need to do something like

$("button.delete").on('click', function(){
    $("input:checkbox[class=checkbox]").each(function () {

    });
});

But honestly at this point I am just trial and error testing code I find online. I'd rather have a clear cut answer and explanation.

Equally how would I spit this out and have php (PDO db connections) process it as an array?

Bruce

Took my hours to get this but here we are

the jquery/ajax:

$(document).ready(function(){
  $('.delete').click(function(){
    var checkValues = $('input[type=checkbox]:checked').map(function(){
      return $(this).val();
    }).get();

  $.ajax({
    url: 'delete_records.php',
    type: 'post',
    data: {ids:checkValues},
    success:function(data){
    }
  });
  });
});

The first function in the jquery grabs all the values from checkbox and sets them as a variable array - checkValues.

The second part secnds the values as an array to the php page.

And the php:

$data = $_POST['ids'];
foreach ($data as $d) {
  $query = $db->prepare("DELETE FROM sites WHERE username=:username AND id=:id");
  $query->bindValue(':username', $username);
  $query->bindValue(':id', $d);
  $query->execute();
}

Sets the array to a variable $data and then runs each result as a foreach loop.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

jQuery AJAX submit form

From Dev

Multi-Page Form Submit

From Dev

Modal form Submission to PHP using Jquery .ajax

From Dev

AngularJS - submit form with checkboxes via ajax

From Dev

how to submit form name and submit button name in ajax form submission

From Dev

Using jQuery AJAX to call a php page on form submission

From Dev

JQuery/Ajax & Spring Rest Multi-part form submit

From Dev

Submit form without reload using jQuery AJAX in PHP MySQL

From Dev

React + Redux: submit multi-component form

From Dev

multi submit buttons multi checkboxes no form jquery ajax php submission

From Dev

AngularJS - submit form with checkboxes via ajax

From Dev

jquery Validation on Multi Step Form

From Dev

Form Submission through Ajax and PHP

From Dev

Ajax form submission on a form created using jquery

From Dev

Ajax Submit Form Self Page - two buttons

From Dev

Ajax + PHP in multi row

From Dev

Using PHP form validation on jQuery form submission

From Dev

PHP form with multiple checkboxes/Bootstrap buttons

From Dev

JQuery/Ajax & Spring Rest Multi-part form submit

From Dev

jQuery ajax form submission to php not working with response from server

From Dev

jQuery continue form submission with selected submit button

From Dev

React + Redux: submit multi-component form

From Dev

Relaying multi-part form data through Ajax to PHP

From Dev

jquery ajax requests are not responding on the new tab after the php form submission

From Dev

Posting multi dimensional form via jquery to php

From Dev

Prevent Form Submission if dynamic field is blank....Php / Jquery / Ajax

From Dev

Submit checkboxes in JSP form submission to Spring controller

From Dev

jQuery submit form and php

From Dev

JQUERY Ajax multi post

Related Related

  1. 1

    jQuery AJAX submit form

  2. 2

    Multi-Page Form Submit

  3. 3

    Modal form Submission to PHP using Jquery .ajax

  4. 4

    AngularJS - submit form with checkboxes via ajax

  5. 5

    how to submit form name and submit button name in ajax form submission

  6. 6

    Using jQuery AJAX to call a php page on form submission

  7. 7

    JQuery/Ajax & Spring Rest Multi-part form submit

  8. 8

    Submit form without reload using jQuery AJAX in PHP MySQL

  9. 9

    React + Redux: submit multi-component form

  10. 10

    multi submit buttons multi checkboxes no form jquery ajax php submission

  11. 11

    AngularJS - submit form with checkboxes via ajax

  12. 12

    jquery Validation on Multi Step Form

  13. 13

    Form Submission through Ajax and PHP

  14. 14

    Ajax form submission on a form created using jquery

  15. 15

    Ajax Submit Form Self Page - two buttons

  16. 16

    Ajax + PHP in multi row

  17. 17

    Using PHP form validation on jQuery form submission

  18. 18

    PHP form with multiple checkboxes/Bootstrap buttons

  19. 19

    JQuery/Ajax & Spring Rest Multi-part form submit

  20. 20

    jQuery ajax form submission to php not working with response from server

  21. 21

    jQuery continue form submission with selected submit button

  22. 22

    React + Redux: submit multi-component form

  23. 23

    Relaying multi-part form data through Ajax to PHP

  24. 24

    jquery ajax requests are not responding on the new tab after the php form submission

  25. 25

    Posting multi dimensional form via jquery to php

  26. 26

    Prevent Form Submission if dynamic field is blank....Php / Jquery / Ajax

  27. 27

    Submit checkboxes in JSP form submission to Spring controller

  28. 28

    jQuery submit form and php

  29. 29

    JQUERY Ajax multi post

HotTag

Archive