mardi 26 mai 2015

jquery checkbox and textbox validation

I have this submit button which will only enable if user entered a word on all textfields as well as chose at least one from my checkboxes. So here's my code:

$(document).ready(function() {
    $('#btnAddUser').attr('disabled', true);

    var checkboxes = $("input[type='checkbox']");
    $('#txtName' && '#txtLastname').on("keyup", action);

    function action() {
        if ($('#txtName' && '#txtLastname').val().length > 0) {
            $('#btnAddUser').attr("disabled", false);
        } else {
            $('#btnAddUser').attr("disabled", true);
        }
    }

    var checkboxes = $("input[type='checkbox']"),
        submitButt = $("#btnAddUser");

    checkboxes.click(function() {
        if ($(this).is(':checked')) {
            $('#btnAddUser').prop("disabled", false);
        } else {
            $('#btnAddUser').prop("disabled", true);
        }
    });
});

my function for textboxes and checkboxes were currently separated, how am I going to join it together in one function so that It won't enable submit button if the user did not entered a word in the textboxes and chose any of the checkboxes available. Thanks! I just really need to get this done as soon as possible.




Aucun commentaire:

Enregistrer un commentaire