Avatar of newbie27
newbie27Flag for United Kingdom of Great Britain and Northern Ireland asked on

Check All checkboxes using JQuery

Hello Experts,
I am displaying search results in the Jquery Flexigrid plugin where I also have added checkbox to each correspoding record. Irrespective whether I select single checkbox or all checkboxes on the page, the script attached is returning values for the records on the page.
I want to pick and process values which are ticked but it is not returning the correct values.
Please can someone have a look into this.
Regards
s
function addToList(){
		if($("#drpLists").val() == 0){
			alert('Please select a list');
		}else{		 
			var result = "";			
			$(".chkRefNos").each( function () {
			
			//result = result + $(this).val() + ", ";
			
			result = result + $(".chkRefNos:checked").val() + ", ";
			
			});
			alert(result);
		};
		 
	}

Open in new window

JavaScript

Avatar of undefined
Last Comment
Graham Hirst

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Graham Hirst

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
newbie27

Hello FSIFM,

Yes you are right I was not checking which one was checked .....thanks for your help,

if(this.checked == true)

this actually have helped...

cheers
sam
ASKER
newbie27

I have another open question, please can you have a look into this as well...
thanks
sam
ASKER
newbie27

thanks
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Graham Hirst

which one as you seem to have 3 open questions
ASKER
newbie27

FSIFM:

I just have noticed, that it is only picking the first checkbox value and repeating the same for any other selection ...
I mean, If I select 2 checkboxes, I am getting 2 alerts both with the same value ... please do you see any other issue here ?

thanks for yur help

      
function addToList(){
   if($("#drpLists").val() == 0){
            alert('Please select a list');
   }else{          
            var result = "";                        
       $(".chkRefNos").each( function () {
       if(this.checked == true){
                  alert($(".chkRefNos:checked").val());
                  result = result + $(".chkRefNos:checked").val() + ", ";
       }                        
       });
//alert(result);
   };                
}      
ASKER
newbie27

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Graham Hirst

try changing:

alert($(".chkRefNos:checked").val());

to

alert($(".chkRefNos").val());