Button to select all checkboxes in a form


I have a form that has a calendar for users to click on certain days. I would like to offer a button for them select all the days, but i'm having trouble. Ways that I've found for making a "check all" button aren't working because I named my check boxes with a "[ ]" at the end because I need them to be an array for the php processing on the submit page.

Here is the javascript code I'm trying to use:

function check_all()
	var z=0;
	var box;
	for (z=0; z<54; z++)
		document.getElementById('day'+z).checked = true;

and here is the html code:

<input type="button" name="Check_All" value="Select All Days" onClick="check_all()"> 
<input type="button" id="clearAll" value="Clear All Days"  onClick="un_check_all();"><br /><br />
	<table >
			<td><input type="checkbox" name="Day[]" id="day0"></td>
			<td><input type="checkbox" name="Day[]" id="day1"></td>
			<td><input type="checkbox" name="Day[]" id="day2"></td>
			<td><input type="checkbox" name="Day[]" id="day3"></td>
			<td><input type="checkbox" name="Day[]" id="day4"></td>


Hi @zoey7907
Name is not the issue.
I tested the above code it is working fine
Once check the console and check what is the error you are getting.
I have modified the code little. Check this


Thank you. I wasn't getting an error message, it simply wasn't checking any of the boxes. I found a way to do it with JQuery. Thanks!!

closed #4

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.