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 Dev

multi submit buttons multi checkboxes no form jquery ajax php submission

From Dev

JQuery/Ajax & Spring Rest Multi-part form submit

From Dev

JQuery/Ajax & Spring Rest Multi-part form submit

From Dev

Submit checkboxes in JSP form submission to Spring controller

From Dev

Modal form Submission to PHP using Jquery .ajax

From Dev

Posting multi dimensional form via jquery to php

From Dev

Multi-Page Form Submit

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 form submission to php not working with response from server

From Dev

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

From Dev

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

From Dev

Form Submission through Ajax and PHP

From Dev

JQUERY Ajax multi post

From Java

jQuery AJAX submit form

From Dev

AngularJS - submit form with checkboxes via ajax

From Dev

AngularJS - submit form with checkboxes via ajax

From Dev

jQuery continue form submission with selected submit button

From Dev

Ajax + PHP in multi row

From Dev

Relaying multi-part form data through Ajax to PHP

From Dev

Ajax form submission on a form created using jquery

From Dev

PHP form with multiple checkboxes/Bootstrap buttons

From Dev

React + Redux: submit multi-component form

From Dev

React + Redux: submit multi-component form

From Dev

jQuery submit form and php

From Dev

Ajax Submit Form Self Page - two buttons

From Dev

Submit form without reload using jQuery AJAX in PHP MySQL

From Dev

Using PHP form validation on jQuery form submission

From Dev

jquery Validation on Multi Step Form

Related Related

  1. 1

    multi submit buttons multi checkboxes no form jquery ajax php submission

  2. 2

    JQuery/Ajax & Spring Rest Multi-part form submit

  3. 3

    JQuery/Ajax & Spring Rest Multi-part form submit

  4. 4

    Submit checkboxes in JSP form submission to Spring controller

  5. 5

    Modal form Submission to PHP using Jquery .ajax

  6. 6

    Posting multi dimensional form via jquery to php

  7. 7

    Multi-Page Form Submit

  8. 8

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

  9. 9

    Using jQuery AJAX to call a php page on form submission

  10. 10

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

  11. 11

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

  12. 12

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

  13. 13

    Form Submission through Ajax and PHP

  14. 14

    JQUERY Ajax multi post

  15. 15

    jQuery AJAX submit form

  16. 16

    AngularJS - submit form with checkboxes via ajax

  17. 17

    AngularJS - submit form with checkboxes via ajax

  18. 18

    jQuery continue form submission with selected submit button

  19. 19

    Ajax + PHP in multi row

  20. 20

    Relaying multi-part form data through Ajax to PHP

  21. 21

    Ajax form submission on a form created using jquery

  22. 22

    PHP form with multiple checkboxes/Bootstrap buttons

  23. 23

    React + Redux: submit multi-component form

  24. 24

    React + Redux: submit multi-component form

  25. 25

    jQuery submit form and php

  26. 26

    Ajax Submit Form Self Page - two buttons

  27. 27

    Submit form without reload using jQuery AJAX in PHP MySQL

  28. 28

    Using PHP form validation on jQuery form submission

  29. 29

    jquery Validation on Multi Step Form

HotTag

Archive