samedi 4 août 2018

How to check whether a checkbox is checked?

Here is something I have now: I've got a checkbox, which I need to verify whether it is selected.

<input type ="checkbox" name="person_info_check" value="0" &nbps>Read and agree!</input>

But when I tried to use the way I had searched through the Internet, I found I couldn't catch the checkbox and thus verify.

This is how I grab the checkbox:

        if($('#person_info_check').is(':checked');){
            if(confirm(Are you sure to submit?)")){
                return true;
            }
            else return false;
        }
        else{
            alert("Please read the file and agree the statement!");
            return false;
        }

And I've also tried this:

        var checkbox = document.getElementsByName("person_info_check");

        if(checkbox.checked==false){
            alert("Please read the file and agree the statement!");
            return false;
        }




Aucun commentaire:

Enregistrer un commentaire