Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
132
rated 0 times [  136] [ 4]  / answers: 1 / hits: 70366  / 12 Years ago, wed, june 6, 2012, 12:00:00

I am having 100 Checkboxes on my web page. For testing purposes I want to tick all those boxes, but manually clicking is time consuming. Is there a possible way to get them ticked?



Perhaps a JavaScript or Chrome Console window, anything?


More From » html

 Answers
23

The most direct way would be to grab all your inputs, filter just the checkboxes out, and set the checked property.



var allInputs = document.getElementsByTagName(input);
for (var i = 0, max = allInputs.length; i < max; i++){
if (allInputs[i].type === 'checkbox')
allInputs[i].checked = true;
}





If you happen to be using jQuery—and I'm not saying you should start just to tick all your checkboxes for testing—you could simply do



$(input[type='checkbox']).prop(checked, true);


or as Fabricio points out:



$(:checkbox).prop(checked, true);

[#85121] Monday, June 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yulissamirandah

Total Points: 493
Total Questions: 115
Total Answers: 94

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;