JSFiddle - React, Tailwind, and code Playground

by amindunited

HTML

<div id="container">
    <input type="checkbox" value="1" name="something[1]"/>
    <input type="checkbox" value="1" name="something[2]"/>
    <input type="checkbox" value="1" name="something[3]"/>
    <input type="checkbox" value="1" name="something[4]"/>
    <input type="checkbox" value="1" name="something[5]"/>
    <input type="checkbox" value="1" name="something[6]"/>
    <input type="checkbox" value="1" name="something[7]"/>
    <input type="checkbox" value="1" name="something[8]"/>
    <input type="checkbox" value="1" name="something[99]"/>
</div>

JavaScript

function check_em () {
    
    var inputs = $("#container").find('input');
    var checked_inputs = new Array();
    console.log(inputs)
    $.each(inputs, function(i, obj){
        if ( obj.checked ){
            
            checked_inputs.push( obj.name.replace('something[', '').replace(']','') )
        }
    })
    console.log("checked_inputs", checked_inputs);
}

$(function(){
    $("input").click(function(e){
        check_em(e)
    })
})