samedi 2 septembre 2017

At least on checkbox required out of a checkbox list dinamically generated [duplicate]

This question already has an answer here:

I have a dynamically generated list of checkboxes where I need to indicate that at least one is required, not all of them, I have this code:

<form action="indexit.php" name="indexit" action="post">
<?php
echo "<li><input type='checkbox' name='indexfiles[]' value='$file' onclick='handleCheckboxRangeSelection(this,event);' />$file</li><br />";
?>

If I add the required, as in the code below, all of them become required, but I need, as I said, only one of the list, whichever...

<form action="indexit.php" name="indexit" action="post">
<?php
echo "<li><input type='checkbox' name='indexfiles[]' value='$file' onclick='handleCheckboxRangeSelection(this,event);' required>$file</li><br />";
?>

I've tried this code with no success:

<script src='http://ift.tt/2nYZfvi'></script>
<script>
$(document).ready(function () {

    $('#indexit').validate({
        rules: {
            indexfiles[]: {
                required: true
            },
        messages: {
            indexfiles[]: {
                required: "you must check at least one from Group 1"
            },
        },
        submitHandler: function (form) { // for demo
            alert('valid form');
            return false;
        }
    });

});
</script>




Aucun commentaire:

Enregistrer un commentaire