Link to home
Start Free TrialLog in
Avatar of newbie27
newbie27Flag for United Kingdom of Great Britain and Northern Ireland

asked on

check all checkboxes

Hello Experts,
I am using the attached script to post ajax data to the server, the user has an option to select records they want to process by ticking the checkbox, i am assuming that if the user did not tick any checkboxes then process all the records available on the page.
in order to do this, i am ticking the checkboxes from the script so that i can post appropriate records ids.
this is actually visible on the page, soon you click on save button user can see the checkboxes being ticked and posted.
i wonder if i can do the same without actually making the check boxes tick visible?
many thanks for your help
regards
sam
Avatar of newbie27
newbie27
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

hope you understand what I have tried to say you here?
thanks for help and time...


function addToList()
{
  if($("#drpLists").val() == 0){
    alert('Please select a list');  
  } 
	
    var result = "";             
    $(".chkRefNos").each( function () 
        {
        if(this.checked == true) {     
             result += "," + $(this).val()  ;
        }
        });
        result = result.substr(1);
            if( result ){
				
										  submitForm('frmList', 'savefields');
					//} 
            } else{
				checkAll("on"); // this is making the tick visible...
				submitForm('frmList', 'savefields'); 	
			} 
  }
 //return false;   
} 
 
 
function checkAll(chkd)
{
$(".chkRefNos").each(function(){
                this.checked = chkd;
            });
}
  

Open in new window

SOLUTION
Avatar of Airyck666
Airyck666
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hielo
>>i am assuming that if the user did not tick any checkboxes then process all the records available on the page
In my opinion, that is just a bad decision. Look at it from the user's perspective. "I did not check anything, why is it processing everything?". Other than the fact that it is counter intuitive, your approach will just lead to complaints.
Having said that, you may choose to check only the check all box (and not check the others), so on the server you will only see one checkbox. The drawback is that if the other checkboxes are not actually checked then you will not receive the ids of those checkboxes. What you are trying to do is just a recipe for a major headache.
Hello Hielo,
Many thanks for your suggestion. I actually have had this "checkAll" check box in the first place, and  a validation before posting the records to save it on the server, either to check any or all as an alert to the user.
But then I was been told to remove  the validation and assume that if the user did not chose to tick any of the check boxes on the page then his intentions are to add all the records, hence I was actually forcing these check boxes to get checked by  checkAll(chkd).

If you still think it is wrong to do this way, then I will let them know and force the user to tick before posting.

thanks for your help/advice
regards
sam

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks hielo,

--> then you don't need any checkall button at all,
ok fine i will remove the checkall button..

please let me know , if its correct to have it like is then?

  checkAll("on"); // this will actually tick all the check boxes, so i can receive it on the other end
 submitForm('frmList', 'savefields');    
             
thanks for your help
>>please let me know , if its correct to have it like is then?
>>checkAll("on");
What I am saying is you don't even need checkAll function at all.
Hielo,
how would I get the ids to process then? as I am passing the record id when the check box is  ticked..! please advice
thanks


>>how would I get the ids to process then?
Now, do you see what I was talking about?