2 Replies - 1097 Views - Last Post: 06 September 2011 - 06:50 PM

#1 eZACKe   User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

jQuery Event for selecting drop down option

Posted 06 September 2011 - 02:55 PM

I have a table full of names. Each name has a checkbox next to it. I want to give the user an option to quickly select all or select none. I do this with a drop down menu.

It works except for in one scenario: When the user selects something that is already selected.

I'll do a run through. Say we have this table:

Zack []
Bob []
Tom []

Then I choose the select All option. Our table looks like this:

Zack [x]
Bob [x]
Tom [x]

Now I deselect Tom manually so that it looks like this:

Zack [x]
Bob [x]
Tom []

Then I decide I want them all selected again so I click Select All option. The table ends up looking like this:

Zack [x]
Bob [x]
Tom []

As you can see, nothing changes. Tom is not selected.

I do know why though. Here's my code:
// select all/none group requests script
$('#dropDownMenu').change(function(){
	if($('#dropDownMenu').val() == "All")
	{
		 $("#groupRequestsTable input:checkbox").attr('checked', true);
	}
	else if($('#dropDownMenu').val() == "None")
	{
		$("#groupRequestsTable input:checkbox").attr('checked', false);
	}
});



The reason the problem is occurring is because I'm using the .change() event, and it's not changing. My problem is I don't know what other events to use. I did a lot of googling and what not and it seems to me that something like what I want doesn't exist.

Does anyone know of some code I could write up myself that would get the job done?

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: jQuery Event for selecting drop down option

#2 Jstall   User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: jQuery Event for selecting drop down option

Posted 06 September 2011 - 06:08 PM

Hi,

I can't think of another event to listen for. Is it necessary you use a select box? This could be accomplished with another checkbox that toggles select all/none. Something like this, which is from a recent thread dealing with this type of functionality.
Was This Post Helpful? 1
  • +
  • -

#3 eZACKe   User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: jQuery Event for selecting drop down option

Posted 06 September 2011 - 06:50 PM

Thanks I ended up using pretty much exactly what you have in the other thread. I did kind of find a workaround for the other way, but I don't like how it looks as much:

// select all/none group requests script
$('#dropDownMenu').change(function(){
	if($('#dropDownMenu').val() == "All")
	{
		 $("#groupRequestsTable input:checkbox").attr('checked', true);
	}
	else if($('#dropDownMenu').val() == "None")
	{
		$("#groupRequestsTable input:checkbox").attr('checked', false);
	}
});

// if user checks boxes without using drop down, default drop down back to "Select..."
$('.requestCheckBox').click(function(){
	$('#dropDownMenu').val("Select...");
});


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1