how to get values on two columns of all checked rows

how to get values on two columns of all checked rows

mynamesefymynamesefy Posts: 5Questions: 1Answers: 0

when click button Get it !!! i need to get value from checkbox value and select option value

https://live.datatables.net/vebenuhu/1/edit

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    You are calling a function called putData in the button's click handler. But I don't see that function anywhere. What have you tried?

    Allan

  • mynamesefymynamesefy Posts: 5Questions: 1Answers: 0

    i had try this option :
    https://live.datatables.net/vebenuhu/2/edit

    but this option doesn't fully answer what I want

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    You'll need to expand on what you are looking for it to do, as I don't quite understand at the moment. The code looks to be working. When you click #ok it will check the values for all checked input checkboxes and add them to an array. That is happening (assuming you've got one or more checkboxes checked it will show in the console).

    If you want the select values as well, then you need to fetch them as well.

    Allan

  • mynamesefymynamesefy Posts: 5Questions: 1Answers: 0

    i don't know how to fetch all values checked input '''tag''' and select tag to an multi-dimentional array.

    because of that, then I tried to replace value all checked checkbox tag by combining value checked checkbox tag value with option tag value and then fetch all checked checkbox tag values to an array.

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    I added a button Get All to your test case:
    https://live.datatables.net/vebenuhu/4/edit

    It gets all the checkbox states (true/false) and select values into their own arrays. Is this what you are looking for?

    It uses column().nodes() and to$() to get all the jQuery nodes in each column. Loops through them to get the checkbox states and select values.

    Kevin

  • mynamesefymynamesefy Posts: 5Questions: 1Answers: 0

    your result when click button Get All, output :
    [true, true, true, false, false]
    ["b", "c", "x", "x", "x"]

    i had try it, but that not what im lookin for

    i want the output (only for checked checkbox values) :
    ["checkboxvalue+optionvalue", "checkboxvalue+optionvalue", "checkboxvalue+optionvalue", etc]

    should I use loop method to combine values array checkboxs and array select option ?

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    This is one of many ways in which that could be done:

       var result = [];
       
       table.rows().every(function () {
         var tr = this.node();
         var checkbox = $('input[type=checkbox]', tr);
    
         if (checkbox.is(':checked')) {
           result.push(checkbox.val() + $('select', tr).val());
         }
       });
      
       console.log(result);
    

    https://live.datatables.net/vebenuhu/5/edit

    Allan

  • mynamesefymynamesefy Posts: 5Questions: 1Answers: 0

    Thank you very much Allan

Sign In or Register to comment.