insert the checkbox values that are selected in accordance? [duplicate]

0

My CH is connected to a field in the database, as the values that are selected are inserted into an array?

    
asked by user67498 29.11.2017 в 19:00
source

1 answer

1

First it is required to generate a variable of type array, later generate a loop and inside the loop using selectors css and jquery you can iterate according to the selected checkboxes that exist ... it would be something like the following:

HTML:

<input type="checkbox" name="check" value="A" />
<input type="checkbox" name="check" value="B" />
<input type="checkbox" name="check" value="C" />
<input type="checkbox" name="check" value="D" />

jQuery:

var arr = [];

$("input:checkbox[name=check]:checked").each(function(){
    arr.push($(this).val());
});

console.log(arr); // print de los items add dentro de tu array...

I hope you find it useful, greetings.

    
answered by 29.11.2017 / 19:10
source