Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript: return not in function?

    i'm getting a "return not in function" error on the return for chkEach()



    does anybody know the general cause of this error because it keeps coming up?



    Thanks for yr time!



    Code:
    //TP
    
    chkEach(FeildIDs,funct)
    
    {
    
     var arrFeilds = new Array();
    
     arrFeilds=document.getElementById(FeildIDs);
    
     var arrErr= new Array();
    
     for(var i=0; i<arrFeilds.length; i++)
    
     {
    
      arrErr.push(funct(arrFeilds[i]));
    
     }
    
     return arrErr;
    
    }


    Rest of code:

    Code:
    //TP
    
    function chkboxRange(chkboxarray, min, minerror, max, maxerror)
    
    {
    
     /*
    
     Creates Array
    
     - var arrName = new Array()
    
      arrName[0]="item1"
    
      arrName[1]="item2"
    
      arrName[2]="item3"
    
     - var arrName=new Array("item1","item2","item3")
    
     - var arrName = ["item1","item2","item3"]
    
     */
    
     var arrSelect =[];
    
     //Cycle thru checkbox array
    
     //since first index=0, length is always 1 more than last index.
    
     for(var i=0;i<chkboxarray.length;i++)
    
     {
    
      if(chkboxarray[i].checked)
    
      {
    
       //if checked, push id into Select array.
    
       arrSelect.push(chkboxarray[i].id);
    
      }
    
     }
    
     var arrError = new Array();
    
     //if min exists & length is less than min, add minerror to arrError array.
    
     if(min && arrSelect.length<min)
    
     {
    
      arrError.push(minerror);
    
     }
    
     //if max exists & length is less than max, add maxerror to arrError array.
    
     if(max && arrSelect.length<max)
    
     {
    
      arrError.push(maxerror);
    
     }
    
     return arrError;
    
    }
    
    /*
    
    This function checks whether the passed parameter is null or blank.
    
    In this we pass the value of the fields as a parameter.
    
    If the str is blank or null, it will return true and otherwise false.
    
    */
    
    function isEmpty(feild)
    
    {
    
     //var str1=trim(str);
    
     var str= feild.value;
    
     /*
    
     http://www.webreference.com/js/column5/index.html
    
     Regular Expression Key:
    
      / - pattern must begin and end with / in Javascript
    
      Modifiers Before or after
    
       g Do global pattern matching.
    
       i Do case-insensitive pattern matching.
    
       m* Treat the string as multiple lines.
    
       s* Treat the string as a single line.
    
       x* Ignore whitespace within a pattern.
    
       * Modifiers that are not supported by Navigator 4.0x and Internet Explorer 4.0.
    
       Examples
    
        /JavaScript/i matches both "javascript" and "JavaScript"
    
      Rule 2: | Seperates alternatives
    
      Rule 4: Assertions
    
       ^ Matches at the beginning of the string.
    
       $ Matches at the end of the string.
    
       \b Matches a word boundary (between \w and \W), when not inside [].
    
       \B Matches a non-word boundary.
    
      Rule 5: Quantifiers
    
       {m,n} Must occur at least m times, but not more than n times.
    
       {n,} Must occur at least n times.
    
       {n} Must occur exactly n times.
    
       * Must occur 0 or more times (same as {0,}).
    
       + Must occur 1 or more times (same as {1,}).
    
       ? Must occur 0 or 1 time (same as {0,1}).
    
      Rule 6: Special Characters
    
       \n Linefeed
    
       \r Carriage return
    
       \t Tab
    
       \v Vertical tab
    
       \f Form-feed
    
       \d A digit (same as [0-9])
    
       \D A non-digit (same as [^0-9])
    
       \w A word (alphanumeric) character (same as [a-zA-Z_0-9])
    
       \W A non-word character (same as [^a-zA-Z_0-9])
    
       \s A whitespace character (same as [ \t\v\n\r\f])
    
       \S A non-whitespace character (same as [^ \t\v\n\r\f])
    
        /abc/gi 
    
     */
    
     //Replace str value with value after run thru regex.
    
     //regex deletes whitespace before the first & after the last alphanumeric character
    
     var trim = str.replace(/^\s+|\s+$/g,"");  
    
    
    
     if(trim == null || trim.length==0)
    
     {
    
      var error='<a href=#'+feild+'>'+feild+'is a required feild.</a>';
    
      return error;
    
     }
    
     else
    
     {
    
      return true;
    
     }
    
    }
    
    //this Keyword - http://www.quirksmode.org/js/this.html
    
    /*
    
    This Function is to find out that whther the value of the field is numeric or not.
    
    Parameter: any value(In this case its a value contained in any field.)
    
    Returns: false if user has not entered the number, true otherwise.
    
    */
    
    function onlyNbr(feild)
    
    {
    
     var str=feild.value;
    
     var pat = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
    
     if(!str.match(pat))
    
     {
    
      var error='<a href=#'+feild+'>'+feild+'should consist of numbers only.</a>';
    
      return error;
    
     }
    
     else
    
     {
    
      return true;
    
     }
    
    }
    
    /*
    
    Function to find out whether the passed id is valid or not.
    
    Paramter: Email Id. In this case vfalue of a field in which email is entered.
    
    Return:  It returns true is the mail is not valid and false in opposite situation.
    
    */
    
    function isValidEmail(feild)
    
    {
    
     var str=feild.value;
    
     var pat = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    
     if(!str.match(pat))
    
     {
    
      var error='<a href=#'+feild+'>'+feild+'is not a valid email address containing a \'@\' and extension (.com, .org, etc).</a>';
    
      return error;
    
     }
    
     else
    
     {
    
      return true;
    
     }
    
    }
    
    //TP
    
    chkEach(FeildIDs,funct)
    
    {
    
     var arrFeilds = new Array();
    
     arrFeilds=document.getElementById(FeildIDs);
    
     var arrErr= new Array();
    
     for(var i=0; i<arrFeilds.length; i++)
    
     {
    
      arrErr.push(funct(arrFeilds[i]));
    
     }
    
     return arrErr;
    
    }
    
    //TP
    
    chkUsual()
    
    {
    
     var arrErr= new Array();
    
     //Concatenate arrays - http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_concat
    
     arrErr=arrErr.concat(chkEach(reqTypeTxt,isEmpty);
    
     //arrErr=arrErr.concat(chkEach(onlyLtr,);
    
     arrErr=arrErr.concat(chkEach(onlyNbr,onlyNbr);
    
     arrErr=arrErr.concat(chkEach(validEmail,isValidEmail);
    
     return arrErr;
    
    }
    
    //TP
    
    chkForm()
    
    {
    
     var arrErr= new Array();
    
     arrErr=arrErr.concat(chkUsual());
    
     if(arrErr)
    
     {
    
      for(var i=0;i<arrErr.length;i++)
    
      {
    
       document.getElementById('faults').innerHTML+=arrErr[i];
    
      }
    
      return false;
    
     }
    
    }
    Last edited by justravis; 08-29-2007 at 07:19 PM.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Missing keyword function.

    function chkEach(FeildIDs,funct)

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    i before e, except after c.

  • #4
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry for the LATE response. Thanks for your time!

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by justravis View Post
    Sorry for the LATE response. Thanks for your time!
    Don't mention it. Only seven years late ......

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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