0

i'm developing a new web site and i want to find out a way to add a bulk delete option.

Inside the web site I have a table that show information about schedule tasks that a user create.

The table that handle this information have these columns...
| TABLE 'schedule_task' | id, name, starting_date, status

I present all the scheduled tasks in a table using AJAX. I also have a delete/edit button that send event to the back-end.

I want to add a button in this table that the user can delete multi (or all /check-all) tasks in one time.

So far i create the button "Bulk Delete"...

   <button type="button" id="bulk_delete" class="btn-xs bulk_delete_button">
   Bulk Delete</button>

that send an event when its clicked...

 $(document).on('click', '.bulk_delete_button', function(event){
    console.log('Bulk Button clicked');                        });

The button send the event successful to console and i see the message when its clicked...

Console log message Bulk Delete Button

Now i add check-boxes at the left of the table so the user can delete multiple tasks at once...

Next step that i made is to create a function that (i want) to take the picks and send to the event (when the bulk delete button clicked) the id's of tasks that the user want to delete...

My try for this so far is...

 function checkBox_Picks(sourse) {
    check_choises=document.getElementsByName('value');
    for(var i in check_choises)
        check_choises[i].checked=source.checked;

     return check_choises                                  }

I try to pass the 'check_choises' that this function returns to an other function ("function results() {....} but i couldnt pass the return from a function to an other because function A(source) --> function B() )

have you any idea how i can pass the picks of the user(id of the tasks) to the Bulk Delete button?

Nikos Kalantas
  • 95
  • 4
  • 11

1 Answers1

0

First you probably need do change checkBox_Picks to actually determine which checkboxes are checked (at the moment you set the state of them by assigning a value to them : check_choises[i].checked=source.checked;):

function checkBox_Picks() {
  var result = []; //This is your array in which the values if a box is checked or not will be written to, ordered as the boxes themselves in document
  check_choices=document.getElementsByName('value');
  for(var i in check_choices)
    result.push(check_choices[i].checked); //Add the 'checked' value to the result

  return result;                                 
}

Now you could just call the function when your event is triggered and store the result in a variable. After that you could do other things with this result or pass it to another function (your 'result'-function for example). This could look like the following:

$(document).on('click', '.bulk_delete_button', function(event){
   console.log('Bulk Button clicked'); 
   var choices = checkBox_Picks(); //Determine the checked boxes
   console.log(choices); //Log the choices
   //Your code here
   //Possibly do something like 'result(choices)'
});
moronator
  • 304
  • 4
  • 11