How to do in JQuery, a function that checks if there is a checkbox selected, if there is any one it enables the delete button, if there is more than 1 it places the text in the plural.
I made the following code:
NOTE: I did the example below in pure javascript, but I would like it to be in JQUERY. And it still has some error that only enables when the last one is marked.
<script>
function verificaChecks() {
var checados=0;
var aChk = document.getElementsByName("chk_IDDel");
for (var i=0;i<aChk.length;i++){
if (aChk[i].checked == true){
checados++;
document.getElementById('btn_Deletar').removeAttribute("disabled");
if(checados >1)
{
document.getElementById("btn_Deletar").value='Deletar registroS';
}
} else {
document.getElementById('btn_Deletar').setAttribute("disabled","disabled");
if(checados >1)
{
document.getElementById("btn_Deletar").value='Deletar registroS';
}
else
{
document.getElementById("btn_Deletar").value='Deletar registro';
}
}
}
}
</script>
<form>
<input type="checkbox" name="chk_IDDel" id="chk_IDDel" value='1' onchange="verificaChecks()" />
<br>
<input type="checkbox" name="chk_IDDel" id="chk_IDDel" value='2' onchange="verificaChecks()" />
<br>
<input type="checkbox" name="chk_IDDel" id="chk_IDDel" value='3' onchange="verificaChecks()" />
<br>
<input type="checkbox" name="chk_IDDel" id="chk_IDDel" value='4' onchange="verificaChecks()" />
<br><br>
<input type="submit" value="deletar registro" id="btn_Deletar" class="btn btn-danger" disabled="true" />
</form>