Wednesday, June 16, 2010

Select/Un Select check boxes with javascript

view:

<%=check_box_tag :id => "select_all" %>

User List
<% @users.each do |user| %>
<%=check_box_tag "recipient[]", :value => "user.email" %>
<% end %>


javascript code:

script type ="text/javascript">
$(function(){
$("#select_all").click(function(){
$flag = $(this).attr('checked');
if ($flag) {
$("input[name='recipient[]']").each(function(){
$(this).attr('checked', true)
});
}else{
$("input[name='recipient[]']").each(function(){
$(this).attr('checked', false)
});
}
});
});

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.