From: jr on 3 Aug 2010 02:04 There are two required fields, bu and error flag, also if zoneid is selected they must also have a value for the zonenm . I am having trouble figuring out where to return the 0 or the 1 so that it returns false or true but I have the right conditions, thanks, function checkscript() { if (ele.search_bu.value ) && (ele.search_error_flag.value ) { if (ele.search_zoneid.value) && (!ele.search_zonenm.value) else{return 0;} } else {return 1;} </script>
From: RobG on 3 Aug 2010 02:25 On Aug 3, 4:04 pm, jr <jlro...(a)yahoo.com> wrote: > There are two required fields, bu and error flag, also if zoneid is > selected they must also have a value for the zonenm . I am having > trouble figuring out where to return the 0 or the 1 so that it returns > false or true but I have the right conditions, > thanks, > function checkscript() { > if (ele.search_bu.value ) && (ele.search_error_flag.value ) > { > if (ele.search_zoneid.value) && (!ele.search_zonenm.value) > > else{return 0;} Why not return a boolean instead of a string? > } > else {return 1;} Where is the closing brace for the function? Why not return boolean true? > </script> Your code would be much easier to read if it was written as: function checkscript() { // If bu and error_flag have a value if (ele.search_bu.value ) && (ele.search_error_flag.value ) { // If zoneid has a value and zonenm doesn't if (ele.search_zoneid.value) && (!ele.search_zonenm.value) { // do something? } else { // if zoneid doesn't have a value, or // if both zoneid and zonenm have values return 0; } // If either bu or error_flag (or both) don't have a value } else { return 1; } } The comments can be removed once you are happy the logic is correct. The formatting and extra braces should stay, they cost nothing to include and make life far more pleasant for others (and usually the athor also) to follow the code. And find mistakes. It should also help with minifying. -- Rob
From: RobG on 3 Aug 2010 02:26 On Aug 3, 4:25 pm, RobG <rg...(a)iinet.net.au> wrote: > On Aug 3, 4:04 pm, jr <jlro...(a)yahoo.com> wrote: > > > There are two required fields, bu and error flag, also if zoneid is > > selected they must also have a value for the zonenm . I am having > > trouble figuring out where to return the 0 or the 1 so that it returns > > false or true but I have the right conditions, > > thanks, > > function checkscript() { > > if (ele.search_bu.value ) && (ele.search_error_flag.value ) > > { > > if (ele.search_zoneid.value) && (!ele.search_zonenm.value) > > > else{return 0;} > > Why not return a boolean instead of a string? Ooops, number. -- Rob
From: Asen Bozhilov on 3 Aug 2010 04:01 jr wrote: > function checkscript() { > if (ele.search_bu.value ) && (ele.search_error_flag.value ) It is really good idea to read the syntax of `If Statement`. if ( Expression ) Statement And from this point: && (!ele.search_zonenm.value) This part should be parse as Statement and in ECMAScript there is not Statement which start with: && Even and Expression Statement. So the expected result here is SyntaxError. Start reading: <URL: http://www.jibbering.com/faq /> <URL: https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide /> And ECMA-262 standard.
From: Jeff North on 3 Aug 2010 04:59 On Mon, 2 Aug 2010 23:04:41 -0700 (PDT), in comp.lang.javascript jr <jlrough(a)yahoo.com> <3de39edf-6b53-4727-9877-13d4735e28bb(a)w15g2000pro.googlegroups.com> wrote: >| There are two required fields, bu and error flag, also if zoneid is >| selected they must also have a value for the zonenm . I am having >| trouble figuring out where to return the 0 or the 1 so that it returns >| false or true but I have the right conditions, >| thanks, >| function checkscript() { >| if (ele.search_bu.value ) && (ele.search_error_flag.value ) >| { >| if (ele.search_zoneid.value) && (!ele.search_zonenm.value) >| >| else{return 0;} >| } >| else {return 1;} >| </script> Please download and install firefox then download and install firebug. Next, learn how to use firebug to single step through your code. You will learn a lot more and also be able to fix a lot of these errors yourself. For example: both if statements don't have a closing ). This would have been caught with the firebug console.
|
Next
|
Last
Pages: 1 2 3 Prev: When window open closed Next: validation has syntax errors [correction] |