Sandy
Sandy

Reputation: 105

How to write the condition to check the validation using jquery or javascript

hello friends,

        $('input[name=checkedRecordsCat]').attr('checked', true);
        $('input[name=checkedRecordsSubCat]').attr('checked', true);
        $('input[name=checkedRecordsAtta]').attr('checked', true);
        $('input[name=checkedRecordsTextComp]').attr('checked', true);
        $('input[name=checkedRecordsVariableText]').attr('checked', true);
        $('input[name=checkedRecordsFreeFormText]').attr('checked', true);

I have this in my page. i need to check if non of them are checked I need to show a popup message. atleast one check box checked I need do return true.

how to write this condition using jquery or javascript

thanks

Upvotes: 1

Views: 318

Answers (1)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196002

Assuming there are no other elements that have a name starting with checkedRecords you can use the starts-with selector combined with the :checked selector

if ( $('input[name^="checkedRecords"]:checked').length ){
   // at least one is checked
   return true;
} else {
   // none is checked
   // show popup here..
}

Upvotes: 7

Related Questions