lundi 30 mars 2015

Check All Not Disabled

Researching on here I found code that checks if a checkbox is disabled and I am attempting to implement it into my code with no luck.


HTML:



<input type="checkbox" name="file1" id="pdf1" class = "pdffiles" value="101SP01.dwg" disabled="disabled"/><label for="pdf1"><button type = "button" class = "btn btn-primary btn-sm hidden-sm hidden-xs"> PDF</button></label><br />
<input type="checkbox" name="file2" id="pdf2" class = "pdffiles" value="101SP02.dwg" /><label for="pdf2"><button type = "button" class = "btn btn-primary btn-sm hidden-sm hidden-xs"> PDF</button></label><br />


JQuery:



function pdf(source) {
$('input[name=pdffiles]').each(function(){
if(!$(this).attr('disabled'))
checkboxes[i].checked = source.checked;
};
};


When I click the checkbox that selects all, it still selects all. Here is the previously working code that selects all as well (before I made the above changes):



function pdf(source) {
checkboxes = document.getElementsByClassName('pdffiles');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}


The goal is to check only the checkboxes that are not disabled.


Also, incase this helps, here is the checkbox that is clicked that runs the code:



<input type="checkbox" onClick="pdf(this)" class = "hidden-xs hidden-sm">




Aucun commentaire:

Enregistrer un commentaire