lundi 19 juin 2023

How do I require at least one checkbox to be selected?

Part of my HTML form looks like this:

<p>Please select your preferred time slot:</p>
<input type="checkbox" id="am" name="am" value="AM">
<label for="am">AM (09:00-13:00)</label><br>
<input type="checkbox" id="pm" name="pm" value="PM">
<label for="pm">PM (13:00-18:00)</label><br>

I'd like for at least one of the checkboxes to be selected as a requirement of the form being submitted. At the moment, if I leave both unselected, the form is still submitted.

I considered using the required property but I can't figure out how to utilise it without making both required.




Aucun commentaire:

Enregistrer un commentaire