My problem is selecting checkboxes are not checking respective texboxes empty or not in javascript. Here is my javascript code: function check(xform) { var chkedBoxes = [], i = 0, inputs = document.xform.getElementsByTagName('input'); while (i<9) { if (inputs[i].type == 'checkbox' && inputs[i].checked && document.xform.quantity[i].value=="" ) { alert('specify the quantity'); return false; } i++; } } Code (markup): My checkboxes are here moving in a loop: <input type="checkbox" name="chkID[]" id="chkID[]" value="<?=$rowSubjectsx['ID']?>"> And my text boxes are also moving in a loop: <input type="text" name="quantity[]" id="quantity[]" size="3"/> Please Help...