justravis Posted August 29, 2007 Share Posted August 29, 2007 I'm getting a "return not in function" error on this code I think I have commented out: Tried searching thru forum for solution to this seemingly common problem, but came up with nothing. /* VJ This function is to trim a string value. This is used to remove white spaces from the string. This returns the string which is trimmed form of paramter. function trim(str) { /* 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 return str.replace(/^\s+|\s+$/g,""); } */ any ideas? Thank you for your time. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted August 29, 2007 Share Posted August 29, 2007 you have an extra */ at the bottom, but just remove all of the commented out code and see if your function works Quote Link to comment Share on other sites More sharing options...
justravis Posted August 29, 2007 Author Share Posted August 29, 2007 ok..i will delete commented code, but isn't the last */ coorespond to the /* at the top? or does something in the code contradict that logic? Thanks again for yr time! Quote Link to comment Share on other sites More sharing options...
justravis Posted August 29, 2007 Author Share Posted August 29, 2007 now the same error occurs on line 170...return for chkEach() //TP 3function chkboxRange(chkboxarray, min, minerror, max, maxerror) 4{ 5 /* 6 Creates Array 7 - var arrName = new Array() 8 arrName[0]="item1" 9 arrName[1]="item2" 10 arrName[2]="item3" 11 - var arrName=new Array("item1","item2","item3") 12 - var arrName = ["item1","item2","item3"] 13 */ 14 var arrSelect =[]; 15 16 //Cycle thru checkbox array 17 //since first index=0, length is always 1 more than last index. 18 for(var i=0;i<chkboxarray.length;i++) 19 { 20 if(chkboxarray[i].checked) 21 { 22 //if checked, push id into Select array. 23 arrSelect.push(chkboxarray[i].id); 24 } 25 } 26 27 var arrError = new Array(); 28 29 //if min exists & length is less than min, add minerror to arrError array. 30 if(min && arrSelect.length<min) 31 { 32 arrError.push(minerror); 33 } 34 35 //if max exists & length is less than max, add maxerror to arrError array. 36 if(max && arrSelect.length<max) 37 { 38 arrError.push(maxerror); 39 } 40 41 return arrError; 42} 43 44/* 45This function checks whether the passed parameter is null or blank. 46In this we pass the value of the fields as a parameter. 47If the str is blank or null, it will return true and otherwise false. 48*/ 49function isEmpty(feild) 50{ 51 //var str1=trim(str); 52 53 var str= feild.value; 54 55 /* 56 http://www.webreference.com/js/column5/index.html 57 Regular Expression Key: 58 / - pattern must begin and end with / in Javascript 59 Modifiers Before or after 60 g Do global pattern matching. 61 i Do case-insensitive pattern matching. 62 m* Treat the string as multiple lines. 63 s* Treat the string as a single line. 64 x* Ignore whitespace within a pattern. 65 * Modifiers that are not supported by Navigator 4.0x and Internet Explorer 4.0. 66 Examples 67 /JavaScript/i matches both "javascript" and "JavaScript" 68 Rule 2: | Seperates alternatives 69 Rule 4: Assertions 70 ^ Matches at the beginning of the string. 71 $ Matches at the end of the string. 72 \b Matches a word boundary (between \w and \W), when not inside []. 73 \B Matches a non-word boundary. 74 Rule 5: Quantifiers 75 {m,n} Must occur at least m times, but not more than n times. 76 {n,} Must occur at least n times. 77 {n} Must occur exactly n times. 78 * Must occur 0 or more times (same as {0,}). 79 + Must occur 1 or more times (same as {1,}). 80 ? Must occur 0 or 1 time (same as {0,1}). 81 Rule 6: Special Characters 82 \n Linefeed 83 \r Carriage return 84 \t Tab 85 \v Vertical tab 86 \f Form-feed 87 \d A digit (same as [0-9]) 88 \D A non-digit (same as [^0-9]) 89 \w A word (alphanumeric) character (same as [a-zA-Z_0-9]) 90 \W A non-word character (same as [^a-zA-Z_0-9]) 91 \s A whitespace character (same as [ \t\v\n\r\f]) 92 \S A non-whitespace character (same as [^ \t\v\n\r\f]) 93 /abc/gi 94 */ 95 96 //Replace str value with value after run thru regex. 97 //regex deletes whitespace before the first & after the last alphanumeric character 98 var trim = str.replace(/^\s+|\s+$/g,""); 99 100 if(trim == null || trim.length==0) 101 { 102 var error='<a href=#'+feild+'>'+feild+'is a required feild.</a>'; 103 return error; 104 } 105 else 106 { 107 return true; 108 } 109} 110 111//this Keyword - http://www.quirksmode.org/js/this.html 112 113/* 114This Function is to find out that whther the value of the field is numeric or not. 115Parameter: any value(In this case its a value contained in any field.) 116Returns: false if user has not entered the number, true otherwise. 117*/ 118function onlyNbr(feild) 119{ 120 var str=feild.value; 121 122 var pat = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; 123 124 if(!str.match(pat)) 125 { 126 var error='<a href=#'+feild+'>'+feild+'should consist of numbers only.</a>'; 127 return error; 128 } 129 else 130 { 131 return true; 132 } 133} 134 135/* 136Function to find out whether the passed id is valid or not. 137Paramter: Email Id. In this case vfalue of a field in which email is entered. 138Return: It returns true is the mail is not valid and false in opposite situation. 139*/ 140function isValidEmail(feild) 141{ 142 var str=feild.value; 143 144 var pat = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/; 145 146 if(!str.match(pat)) 147 { 148 var error='<a href=#'+feild+'>'+feild+'is not a valid email address containing a \'@\' and extension (.com, .org, etc).</a>'; 149 return error; 150 } 151 else 152 { 153 return true; 154 } 155} 156 157//TP 158chkEach(FeildIDs,funct) 159{ 160 var arrFeilds = new Array(); 161 arrFeilds=document.getElementById(FeildIDs); 162 163 var arrErr= new Array(); 164 165 for(var i=0; i<arrFeilds.length; i++) 166 { 167 arrErr.push(funct(arrFeilds[i])); 168 } 169 170 return arrErr; 171} 172 173//TP 174chkUsual() 175{ 176 var arrErr= new Array(); 177 178 //Concatenate arrays - http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_concat 179 180 arrErr=arrErr.concat(chkEach(reqTypeTxt,isEmpty); 181 //arrErr=arrErr.concat(chkEach(onlyLtr,); 182 arrErr=arrErr.concat(chkEach(onlyNbr,onlyNbr); 183 arrErr=arrErr.concat(chkEach(validEmail,isValidEmail); 184 185 return arrErr; 186} 187 188//TP 189chkForm() 190{ 191 var arrErr= new Array(); 192 arrErr=arrErr.concat(chkUsual()); 193 194 if(arrErr) 195 { 196 for(var i=0;i<arrErr.length;i++) 197 { 198 document.getElementById('faults').innerHTML+=arrErr[i]; 199 } 200 201 return false; 202 } 203} Quote Link to comment Share on other sites More sharing options...
justravis Posted August 31, 2007 Author Share Posted August 31, 2007 forgot to put the word, "function" 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.