jQuery - getting checked items in name array -
http://jsfiddle.net/3kwchkf6/1/
$('[name^="item"]').each(function(){ if ($(this).prop('checked')) { itemcheckedlist.push($(this).attr('name')); } }); console.log(itemcheckedlist);
hi returns ["item[2001]", "item[2090]"]
i want return [2001, 2090]
i thinking maybe solution include regex somehow or serialize somehow? thanks.
you can use .substring()
$('[name^="item"]').each(function(){ if ($(this).prop('checked')) { var start = $(this).attr('name').indexof('[')+1; var end = $(this).attr('name').indexof(']'); itemcheckedlist.push($(this).attr('name').substring(start, end)); } });
Comments
Post a Comment