getting the names of elements in JS/jQuery

Posted by Mala on Stack Overflow See other posts from Stack Overflow or by Mala
Published on 2010-05-18T17:43:13Z Indexed on 2010/05/18 17:50 UTC
Read the original article Hit count: 173

Filed under:
|
|

I have some checkbox inputs like so:

<input type="checkbox" name="1" class="filter"/>
<input type="checkbox" name="2" class="filter"/>
...etc...

I'm trying to write a function where any time a checkbox is selected, it generates a string with all the names concatenated. Here's what I have so far:

$('.filter').click(function(event){
    var filters = $('.filter').toArray();
    var fstr = "";
    for (f in filters)
    {
        fstr = fstr+","+f.name;
    }
    alert(fstr);
});

The names keep coming up as 'undefined', though (i.e. the alert returns ,undefined,undefined,undefined,undefined,undefined,undefined). How do I access the names?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery