Data validation help PLEASE!!

Results 1 to 2 of 2

Thread: Data validation help PLEASE!!

  1. #1
    Join Date
    Dec 1969

    Default Data validation help PLEASE!!

    I am running checks on text fields to make sure that they are numeric entries. I use an onChange to do this. The onChange calls a function which calls another function to do the validation. That all works fine. But when the user submits the page, I want to do one more "batch" validation. I use onSubmit to call a 3rd function, which in turn calls function 1 that calls function 2....let me show the code:<BR><BR>function batchCheckIt(24){<BR> var y=0<BR> for (var z=0;z&#060;24;z++){<BR> if(checkIt(z)){<BR> }<BR> else{<BR> y++<BR> }<BR> }<BR> if(y==0){<BR> return true<BR> }<BR> else{<BR> return false<BR> }<BR>}<BR><BR>function isNumber(inputStr){<BR> for (var zz=0;zz&#060;inputStr.length;zz++){<BR> var oneChar = inputStr.substring(zz, zz+1)<BR> if (oneChar &#060; "0" &#124&#124 oneChar &#062; "9"){<BR> alert("Please Enter Only Numeric Quantities")<BR> return false<BR> }<BR> }<BR> return true<BR>}<BR><BR>function checkIt(test){<BR> inputStr = ProductForm.Quantity[test].value<BR> if (isNumber(inputStr)){<BR> }<BR> else{<BR> ProductForm.Quantity[test].focus()<BR> ProductForm.Quantity[test].select()<BR> }<BR>}<BR><BR>My form declaration looks like:<BR>&#060;form method=&#039post&#039 name=&#039ProductForm&#039 onSubmit=&#039return batchCheckIt(24)&#039&#062;<BR><BR>In batchCheckIt, I use a for loop to go through all 24 text boxes called Quantity. What happens is it goes through and tells me when I have a Quantity that is not numeric, but the page still gets submitted. I am just a little confused with returning false, I think thats where my problem lies.<BR><BR>Thanks for any help!!<BR>CARRIE-BERRY!

  2. #2
    Join Date
    Dec 1969

    Default RE: Data validation help PLEASE!!

    well I&#039ve never seen a value passed to a function as you have in batchCheckIt! I would have coded<BR><BR>function batchCheckIt(numChecks){<BR>var y=0<BR>for (var z=0;z&#060;numChecks;z++){<BR><BR>...but anyway, your checkIt funciton does not explcitly return true or false, so won&#039t the default be true? therfore y will always be zero and batchCheckIt will always return true and so the form submits<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts