I want to check my values are numeric or not.I have been loosing my patients for why my for loop is not working ??.it checks only first value and gets stopped later.
Here is my code
js
then calling it hereCode JavaScript:function NumericVal(fieldList1) { var field1=new Array(); field1=fieldList1.split("~"); //alert(field1); var counter=0; for(i=0;i<field1.length;i++) { //alert(document.getElementById(field1[i]).value); if((document.getElementById(field1[i]).value !="") && ( IsNumeric(document.getElementById(field1[i]).value)==false)) { document.getElementById(field1[i]).style.backgroundColor="#FF0000"; counter++; } } //i++; if(counter > 0) { alert("Please enter only numeric values"); return false; } else { return true; } } function IsNumeric(strString) // check for valid numeric strings { var strValidChars = "0123456789.-"; var iChars = "`~=!@#$%^&*()<>+_[]{}\\;:\"\'?\/"; var strChar; var blnResult = true; if (strString.length == 0) return false; // test strString consists of valid characters listed above for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; //alert("Please enter only numeric values"); } } return blnResult; }
Can anyone why my for loop is not working?Code JavaScript:var checkValidation1= NumericVal('units~units_size'); if((checkValidation1==true) { //do updation }
Thanks in advance.



it checks only first value and gets stopped later.







Bookmarks