I have a group of Checkbox options for 7 Days all with the same name of "sessionDays." I have used the following code to count the number of checked checkboxes:
var totalDays = document.querySelectorAll('.sessionDays input[type="checkbox"]:checked').length;
Now, I am trying to display a list of selected checkboxes in HTML using Javascript without using jQuery. I have searched through various resources but have not found a solution.
Below is my HTML:
<div class="days sessionDays">
<label>Select Session Days</label>
<p class="text-muted">Choose the specific days you wish to attend training.</p>
<div class="form-check">
<input class="form-check-input weekend" type="checkbox" value="1" id="sessionSunday" name="sessionDays" onFocus="startCalc();" onBlur="stopCalc();" onclick="resetMorning();">
<label class="form-check-label" for="sessionSunday">
Sunday
</label>
</div>
<div class="form-check">
<input class="form-check-input weekday" type="checkbox" value="1" id="sessionMonday" name="sessionDays" onFocus="startCalc();" onBlur="stopCalc();" onclick="resetEvening();">
<label class="form-check-label" for="sessionMonday">
Monday
</label>
</div>
<div class="form-check">
<input class="form-check-input weekday" type="checkbox" value="1" id="sessionTuesday" name="sessionDays" onFocus="startCalc();" onBlur="stopCalc();" onclick="resetEvening();">
<label class="form-check-label" for="sessionTuesday">
Tuesday
</label>
</div>
<div class="form-check">
<input class="form-check-input weekday" type="checkbox" value="1" id="sessionWednesday" name="sessionDays" onFocus="startCalc();" onBlur="stopCalc();" onclick="resetEvening();">
<label class="form-check-label" for="sessionWednesday">
Wednesday
</label>
</div>
<div class="form-check">
<input class="form-check-input weekday" type="checkbox" value="1" id="sessionThursday" name="sessionDays" onFocus="startCalc();" onBlur="stopCalc();" onclick="resetEvening();">
<label class="form-check-label" for="sessionThursday">
Thursday
</label>
</div>
<div class="form-check">
<input class="form-check-input weekday" type="checkbox" value="1" id="sessionFriday" name="sessionDays" onFocus="startCalc();" onBlur="stopCalc();" onclick="resetEvening();">
<label class="form-check-label" for="sessionFriday">
Friday
</label>
</div>
<div class="form-check">
<input class="form-check-input weekend" type="checkbox" value="1" id="sessionSaturday" name="sessionDays" onFocus="startCalc();" onBlur="stopCalc();" onclick="resetMorning();">
<label class="form-check-label" for="sessionSaturday">
Saturday
</label>
</div>
</div>
Check out the JSFiddle link for reference: http://jsfiddle.net/humanware/rjfjp2mL/