Solved

check all checkboxes

Posted on 2008-06-15
9
423 Views
Last Modified: 2008-07-03
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
0
Comment
Question by:newbie27
  • 4
  • 4
9 Comments
 
LVL 8

Author Comment

by:newbie27
ID: 21788493
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

0
 
LVL 2

Assisted Solution

by:Airyck666
Airyck666 earned 50 total points
ID: 21788936
I know this isn't what you are asking but maybe it would be better to have them all checked by default.  This way is clearer to the user that they will all be processed without any action on their part.
0
 
LVL 82

Expert Comment

by:hielo
ID: 21789208
>>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.
0
 
LVL 8

Author Comment

by:newbie27
ID: 21789419
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

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 82

Accepted Solution

by:
hielo earned 450 total points
ID: 21789491
>>If you still think it is wrong to do this way
I'm not saying that it is "wrong" in the strict sense of the word. It is counter-intuitive. But since you were told

" 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"

then I guess you will just have to comply with the request. The best you can do is explain the counter-intuitiveness of that approach. Having said that, then you don't need any checkall button at all, since you will be assuming that everything is checked.
0
 
LVL 8

Author Comment

by:newbie27
ID: 21789519
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
0
 
LVL 82

Expert Comment

by:hielo
ID: 21789525
>>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.
0
 
LVL 8

Author Comment

by:newbie27
ID: 21789567
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


0
 
LVL 82

Expert Comment

by:hielo
ID: 21789694
>>how would I get the ids to process then?
Now, do you see what I was talking about?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
date format angularjs2 16 40
indexOf() 2d array value 2 39
radio button value 3 45
Add Background to a PDF Programmatically 1 21
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now