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()

fiddle

$('[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

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -