mardi 21 novembre 2017

How to compare checkbox values in a javascript for loop

I have a jquery appended, list of checkboxes.when i click to one checkbox it should compare with the last checkbox checked values.and if both checked values is equal it should give a alert to the user.please give some solution for this..

my code is-----------

        var GlobalCheckedTaxId = new Array();
        $("input[id^='InvoiceCheckbox_']").change(function () {


            var id = $(this).attr('id');

            if (id != 'InvoiceCheckbox_')
                var lastChar = id.split("_").pop();
            else
                lastChar = '';

            if (this.checked) {
                var CurrentTaxId = ($('#TaxId' + lastChar).text());

                for (var v=0 ; v < GlobalCheckedTaxId.length; v++) {
                    if (GlobalCheckedTaxId[v] == CurrentTaxId)
                        alert("Not allowed to have same Taxes");

                }
                GlobalCheckedTaxId.push = CurrentTaxId;

            }
            else {
                GlobalCheckedTaxId.push = 0;
            }

Thanks Sumit




Aucun commentaire:

Enregistrer un commentaire