1

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)

2
  • can you remove the onclick attribute of the element. Also if you paste your markup and ensure it validates at w3c. Commented Aug 13, 2009 at 10:22
  • You are missing = after input type attribute. Commented Aug 13, 2009 at 10:26

2 Answers 2

6

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');  
});
Sign up to request clarification or add additional context in comments.

1 Comment

no reaction, not even an error :-/ & and i have included my js file.. :)
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.