I have a small form with 6 input boxes. A number is put in each box and totaled in a 7th box.
I want to check that a number was entered in each box. If not then report an error.
My code works if a non-numeric character is entered in the first box, but not for boxes 2 to 6.
This is my jquery code. In the html each textbox has the same name "sum_cc" the total box is "ac". I am using the same name for each input box to sum the values as entered. My understanding was for each box after typing in it the code below would execute and either report an error or sum the values as entered.
- $(document).ready(
function(){
$("input[name^=sum_cc]").keyup(function(){
var cqcc = $("input[name^=sum_cc]").val();
if (isNaN(cqcc) || cqcc == ''){
alert ("Please enter a value!");
$("input[name^=sum_cc]").addClass('error');
} else {
$("input[name^=sum_cc]").sum("keyup","#ac");
$("input[name^=sum_cc]").removeClass('error');
}
}); }
); Any insight on why only the first box is error checked is appreciated.
Thanks