codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Javascript: return not in function?  justravis at 19:36 on Wednesday, August 29, 2007
 

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!



//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));

}

return arrErr;

}



Rest of 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.checked)

{

//if checked, push id into Select array.

arrSelect.push(chkboxarray.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));

}

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;

}

return false;

}

}

  Re: Javascript: return not in function?  arash farhad at 10:40 on Thursday, March 11, 2010
 

Beautiful blog with great informational content. Mostly certifications related and function related topics are really very good. <a href="http://www.latest-testking.com/cisco-640-863.html">testking 640-863</a>, <a href="http://www.latest-testking.com/microsoft-70-536.html">testking 70-536</a> and <a href="http://www.latest-testking.com/microsoft-70-620.html">testking 70-620</a> are also good topics. Thanks for this great sharing.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Text wrapping on C# webforms buttons
•  Re: Replacing patterns a^b with pow(a,b)
•  Re: Problem - Object doesn`t support this property or method
•  great sight
•  Re: JavaScript: Not working in Firefox 3.x
•  Re: Difference between two dates including From & To date
•  Re: How to highlight text WITHIN a JTable cell?
•  Re: Javascript: return not in function?
•  Re: How to concatenate a string and a variable using perl?


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010