Please help..... My problem is that checkboxes are not checking respective textboxes empty or not.Here is my code: function check(xform) { i = 0, inputs = document.xform.getElementsByTagName('input'); while (i<9) { if (inputs.type == 'checkbox' && inputs.checked) { if(document.getElementById('quan[]').value=="") { alert('specify the quantity'); return false; } } i++; } } My checkboxes are moving in a loop: <input type="checkbox" name="chkID[]" id="chkID[]" value="<?=$rowSubjectsx['ID']?>"> Textboxes are also moving in a loop: <input type="text" name="quantity[]" id="quan[]" size="3"/> Please help............
you don't have an onclick event in your checkbox code: <input type="checkbox" name="chkID[]" id="chkID[]" value="<?=$rowSubjectsx['ID']?>" onclick="check(document.forms[0]);"> Also, I wouldn't use [] in the Id and Name tags of the checkboxes and text boxes, but that's just me. Never tried it, but it seems like you're making it more complicated than it needs to be.