jquery vs. checkboxes

Is there a better way to toggle a single checkbox?

Page 1 of 1

1 Replies - 482 Views - Last Post: 26 February 2009 - 02:45 PM

#1 Jael  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-February 09

jquery vs. checkboxes

Posted 26 February 2009 - 02:21 PM

Hi all,

I am new to this forum and hope someone can direct me a little..

I have a checkbox that needs to be checked/unchecked under the following rules..

if any checkboxes with id like "REQ_ACCT_LAB_" are checked, then check it
if all of the checkboxes with id like "REQ_ACCT_LAB_" are unchecked, then uncheck it.

Is there a better way of doing this?

heres my code:

			if ($("input[name^=REQ_ACCT_LAB_]").is(":checked")) 
			{ 
				$("input[name=MY_CHK]").attr("checked","checked"); 
			} 
			else 
			{ 
				$("input[name=MY_CHK]").attr("checked",""); 
			} 
			


Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: jquery vs. checkboxes

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: jquery vs. checkboxes

Posted 26 February 2009 - 02:45 PM

There isn't much you can do here - except maybe trim down your selector a bit:
var new_state = '';
if($("input[name^=REQ_ACCT_LAB_]:checked")) {
    new_state = 'checked';
}
$("input[name=MY_CHK]").attr("checked",new_state);


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1