deepson2 Posted January 25, 2010 Share Posted January 25, 2010 I want to check my values are numeric or not. i have been loosing my patients for why my for loop is not working here. :'( it checks only first value and gets stopped later. Here is my code js 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; } then calling it here var checkValidation1= NumericVal('units~units_size'); if((checkValidation1==true) { //do updation } Can anyone why my for loop is not working? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
kael.shipman Posted January 25, 2010 Share Posted January 25, 2010 What does your HTML look like? It should include the following: <input type="text" id="units" name="units" value="1" /> <input type="text" id="units_size" name="units_size" value="1" /> If that's not the problem, you'll have to describe a little better what's happening. Where is it stopping? What alerts do you get? Etc.... Also, try developing in Firefox and downloaded FireBug. That will tell you exactly what's going on! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.