Hello Everyone, In this tutorial, I am providing a JavaScript Code that helps you check all checkboxes presented on the page. You can execute this javascript code via your browser developer console. So let's see how we can do that.
After completing this unit you'll able to:
- Execute JavaScript Code via browser console.
Code Snippet 1
(function() { var aa= document.getElementsByTagName("input"); for (var i =0; i < aa.length; i++){ if (aa[i].type == 'checkbox') aa[i].checked = true; } })()
Code Snippet 2
(function() { var aa = document.querySelectorAll("input[type=checkbox]"); for (var i = 0; i < aa.length; i++){ aa[i].checked = true; } })()
How to Execute?
Step 1: Right Click on your web page, then click on Inspect or Press F12.
Step 2: Select Console from the menu bar.
Step 3: Copy any of the above-provided javascript code snippets and paste into the console and then hit enter.
Hope your all checkboxes are checked.
See also:
- System.ListException: Duplicate id in list error in Salesforce
- Submit Approval Process using Apex
- Calculate Business Days in Salesforce
Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.
Thank you.
18 Comments
This isn't working!!
ReplyDeleteWorked for me but when i saved the changes on the web page and then reloaded they were no longer checked
ReplyDeleteWorked fine for me, thanks
ReplyDeleteOnly this will work:
ReplyDeletevar aa = document.querySelectorAll("input[type=checkbox]");
for (var i = 0; i < aa.length; i++){
aa[i].checked = true;
}
When I do this, it does select the checkboxes HOWEVER, the website (LinkedIn) does not accept them as checked. They will all be checked and it will still say (0 selected). Is there any work around to fix this? Thank you so much!
ReplyDeletehi Sydney, Basically this article has been written keeping salesforce in mind. so please use it in salesforce.
DeleteThank you
Hi! If I wanted to use a similar script, but to tick say 10-20 specific checkboxes from a long list, not all checkboxes, where would I add the ID of the checkbox, or how would I do this? Thanks!
ReplyDeleteyes, you can build an array of checkbox id after that loop through each id of array to make checkbox checked, but I would suggest one more solution please set class attribute of all check-boxes that you want to checked and then use following code sample to make them checked.
Deleteinput type="checkbox" class="chk"
function makechecked() {
var chkboxes=document.getElementsByClassName('chk');
for (var i = 0; i < chkboxes.length; i++){
chkboxes[i].checked = true;
}
}
Thanks Bro!
ReplyDeleteI checked all input in web site, really thansk!
Glad to know, It's helpful for you, Thank you..!
Deletei'm a student from singapore. it works perfectly. thank you sir for the sharing :)
ReplyDeleteThank you!
DeleteDoesn't work. The checkboxes get selected, but the selections don't get registered.
ReplyDeleteThis is only to make checkbox checked, not to saved the checked response.
DeleteThanks...!
Is there a way to make this work in Docusign? The checkboxes appear on the page, but they no longer appear checked after saving the document.
ReplyDeleteNo this is not for docusign. sorry for that.
Deleteif it is possible to modify this code so that we can uncheck all checked box and check all unchecked boxes in one step. For example if in webpage the left side contains check boxes which are already checked and right side has empty checkboxes to be checked. I want to inverse these so that the unchecked boxes on right should get checked and checked boxes on left gets unchecked. It would be helpful if there is a solution for this . I hope I didn't confuse you
ReplyDeleteHi, Yes we can achieve your mentioned requirement using below sample code:
Delete(function() {
var aa= document.getElementsByTagName("input");
for (var i =0; i < aa.length; i++){
if (aa[i].type == 'checkbox'){
if(aa[i].checked)
aa[i].checked = false;
else
aa[i].checked = true;
}
}
})()
Post a Comment