views:

309

answers:

3

Hey people

I'm trying to get all of my checkboxes to be checked when clicking a link

looks like this: <a href='javascript:;' onclick="$.overall.selectAll();">select all</a>

inputs in a loop: <input type="checkbox" name="delete[$i]" value="1" />

jquery code:

var checked_status = this.checked;

    $("input[name=delete]").each(function() {
    this.checked = checked_status;
});

Can someone help me get it to check all.. ?

When clicking at the select all link, nothing seems to happen.. (not even an error)

+1  A: 

You're going to want to use the [name^=delete] selector ("starts with"), since your checkboxes names aren't exactly "delete", they're "delete[X]' for some number X.

Amber
+5  A: 

Try the following.

Updated. The handler is tied to an anchor therefore there will be no this.checked attribute available.

$("#select_all").click(function(){
    $("input[name^=delete]").attr('checked',  'checked');  
});
redsquare
william
+2  A: 

jQuery Tutorial: Select All Checkbox

CD
thaks, i'm familiar with the link you added. I just want it to be link, and not a checkbox to check them all
william
chanan a ganan
avnic