validation has syntax errors

J

jr

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>
 
R

RobG

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.
 
A

Asen Bozhilov

jr said:
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.
 
J

Jeff North

On Mon, 2 Aug 2010 23:04:41 -0700 (PDT), in comp.lang.javascript jr
<[email protected]>
| 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.
 
R

Richard Cornford

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.

Is it possible to single step through code that contains syntax
errors?

Richard.
 
J

jr

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.

thanks that was it.
 
J

jr

Why not return a boolean instead of a string?


Where is the closing brace for the function? Why not return boolean
true?


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.

okay, there are no syntax errors now but it still doesn't validate.
Just to double check I'm posting it with
the comments and logic how I think it should be. If there isn't an
error here does that mean there is an error in the html
that is blocking the validation from happening? thanks,

function checkscript() {
// If bu and error_flag have a value return 0, if zoneid has a value
without zonenm proceed to next check
if (ele.search_bu.value && ele.search_error_flag.value ) {
// If zoneid has a value and zonenm does not have a value
return false
if (ele.search_zoneid.value && !ele.search_zonenm.value) {
return 1;
} 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;
}
}
 
J

jr

Why not return a boolean instead of a string?


Where is the closing brace for the function? Why not return boolean
true?


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.

THis is the submit button from view source:
<td colspan='13' align='center'><input type='submit' name='submit1'
value = ' Search' onSubmit=" return checkscript();">

Is there anything wrong with my submit button? thanks,
 
J

Jeff North

On Tue, 3 Aug 2010 03:59:19 -0700 (PDT), in comp.lang.javascript
Richard Cornford <[email protected]>
| On Aug 3, 9:59 am, Jeff North wrote:
| > On Mon, 2 Aug 2010 jr wrote:
| <snip>
| > >| function checkscript() {
| > >|   if (ele.search_bu.value ) && (ele.search_error_flag.value )
| <snip>
| >
| > 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.
|
| Is it possible to single step through code that contains syntax
| errors?

I wouldn't know as my code never has syntax errors.
 
T

Tim Streater

Richard Cornford said:
Is it possible to single step through code that contains syntax
errors?

Are you pulling my leg? Why would you want to do that? Code with syntax
errors has no meaning. You fix the errors and then proceed.
 
R

Richard Cornford

Are you pulling my leg? Why would you want to do that? Code
with syntax errors has no meaning. You fix the errors and then
proceed.

I was trying to point out that the proposition that single stepping
thorough the code with a debugger should be attempted by the OP is
inappropriate when the code in question clearly contains syntax errors
and so will not even compile, let alone run.

Richard.
 
R

Richard Cornford

I wouldn't know as my code never has syntax errors.

The answer is that code containing syntax errors cannot be complied,
so cannot be executed and so cannot be single stepped through. Better
advice for a beginner would be to use/look at the error console, or
whatever error reporting mechanism the browser(s) they are using
provides, and start learning to understand the messages it produces.
Where syntax errors are going unnoticed that is more the level of
information that the OP needs.

Richard.
 
T

Tim Streater

Richard Cornford said:
I was trying to point out that the proposition that single stepping
thorough the code with a debugger should be attempted by the OP is
inappropriate when the code in question clearly contains syntax errors
and so will not even compile, let alone run.

Righto, sorry.
 
J

Jeff North

On Tue, 3 Aug 2010 10:17:40 -0700 (PDT), in comp.lang.javascript
Richard Cornford <[email protected]>
| On Aug 3, 2:44 pm, Jeff North wrote:
| > Richard Cornford wrote:
| >>| On Aug 3, 9:59 am, Jeff North wrote:
| >>|> On Mon, 2 Aug 2010 jr wrote:
| >>|<snip>
| >>|>>| function checkscript() {
| >>|>>| if (ele.search_bu.value ) && (ele.search_error_flag.value )
| >>|<snip>
| >>|>
| >>|> 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.
| >>|
| >>| Is it possible to single step through code that contains syntax
| >>| errors?
| >
| > I wouldn't know as my code never has syntax errors.
|
| The answer is that code containing syntax errors cannot be complied,
| so cannot be executed and so cannot be single stepped through. Better
| advice for a beginner would be to use/look at the error console, or
| whatever error reporting mechanism the browser(s) they are using
| provides, and start learning to understand the messages it produces.
| Where syntax errors are going unnoticed that is more the level of
| information that the OP needs.

Sweetheart, go back to my origin post and you will see that I did
mention the console. A section that *you* snipped!
 
R

RobG

THis is the submit button from view source:
<td colspan='13' align='center'><input type='submit' name='submit1'
value = ' Search' onSubmit=" return checkscript();">

Is there anything wrong with my submit button? thanks,

Yes. Input elements don't have an onsubmit attribute so your listener
is not being called. Form elements do, move the onsubmit listener to
the form.
 
T

Thomas 'PointedEars' Lahn

Jeff said:
Sweetheart,

Given your rather naive response to Richards thought-provoking question,
there is no reason for you to feel attacked by Richard's explanation, and no
need to fight back anyway. I think an apology from you to Richard is in
order.
go back to my origin post and you will see that I did
mention the console. A section that *you* snipped!

However, while Firebug is certainly a useful tool for Web developers, it
does not take the Firebug Console for a syntax error in a client-side script
to be displayed. There is a *built-in* Error Console in most Mozilla-based
browsers that can be triggered with a menu item (the Tools menu has it in
Iceweasel 3.6.3) or entering `javascript:' in the Location Bar. That hint
suffices for an answer to a beginner at that position in the learning curve.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top