Javascript causes entire script to fail on web page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Taz Lake

    Javascript causes entire script to fail on web page

    Any JavaScript folks want to take a shot at this? I have a larger
    JavaScript that is doing form validation (I can provide it if needed).
    But this particular piece of code causes the entire script to fail
    (i.e., not execute) and allows the form to be submitted. As soon as I
    remove it, the validation works fine.

    if (employment_sta tus.selectedInd ex == 3 ||
    employment_stat us.selectedInde x == 4 ||
    employment_stat us.selectedInde x == 5 ||
    employment_stat us.selectedInde x == 6) && (contract_end_d ate.value ==
    "")
    {
    alert ("You must select an end date for the new hire if they are a
    contractor or temporary employee in order to submit the New Hire
    Form.")
    employment_stat us.focus()
    return false
    }

    Any help is appreciated as I've looked at this quite and bit nothing
    jumps out. Please reply to the board so all can benefit.

    Thanks,
    Taz
  • Lasse Reichstein Nielsen

    #2
    Re: Javascript causes entire script to fail on web page

    taz@humanthinkt ank.com (Taz Lake) writes:

    I assume "employment_sta tus" is a declared variable that points to
    a select element.
    [color=blue]
    > if (employment_sta tus.selectedInd ex == 3 ||[/color]
    ^ parenthesis begin
    [color=blue]
    > employment_stat us.selectedInde x == 4 ||
    > employment_stat us.selectedInde x == 5 ||
    > employment_stat us.selectedInde x == 6) && (contract_end_d ate.value ==[/color]
    parenthesis end-^ ^^-syntax error

    This would have been caught by JSLint:
    <URL: http://www.crockford.com/javascript/jslint.html >
    It's error message is:
    4) : error at character 39: Expected '{' and instead saw '&&'.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Lee

      #3
      Re: Javascript causes entire script to fail on web page

      Taz Lake said:[color=blue]
      >
      >Any JavaScript folks want to take a shot at this? I have a larger
      >JavaScript that is doing form validation (I can provide it if needed).
      > But this particular piece of code causes the entire script to fail
      >(i.e., not execute) and allows the form to be submitted. As soon as I
      >remove it, the validation works fine.
      >
      >if (employment_sta tus.selectedInd ex == 3 ||
      >employment_sta tus.selectedInd ex == 4 ||
      >employment_sta tus.selectedInd ex == 5 ||
      >employment_sta tus.selectedInd ex == 6) && (contract_end_d ate.value ==
      >"")[/color]

      Whatever browser you're using should be pointing out the syntax
      error in that "if" statement.

      The entire expression to be evaluated must be contained in parentheses.
      You have two sets of parentheses joined by an && operator.
      Add an outer pair, enclosing the entire expression.

      Comment

      • Mick White

        #4
        Re: Javascript causes entire script to fail on web page

        Taz Lake wrote:
        [color=blue]
        > Any JavaScript folks want to take a shot at this? I have a larger
        > JavaScript that is doing form validation (I can provide it if needed).
        > But this particular piece of code causes the entire script to fail
        > (i.e., not execute) and allows the form to be submitted. As soon as I
        > remove it, the validation works fine.
        >
        > if (employment_sta tus.selectedInd ex == 3 ||
        > employment_stat us.selectedInde x == 4 ||
        > employment_stat us.selectedInde x == 5 ||
        > employment_stat us.selectedInde x == 6) && (contract_end_d ate.value ==
        > "")
        > {
        > alert ("You must select an end date for the new hire if they are a
        > contractor or temporary employee in order to submit the New Hire
        > Form.")
        > employment_stat us.focus()
        > return false
        > }
        >
        > Any help is appreciated as I've looked at this quite and bit nothing
        > jumps out. Please reply to the board so all can benefit.
        >
        > Thanks,
        > Taz[/color]

        employment_stat us= [valid reference here]
        contract_end_da te=[valid reference here]
        // valid reference should include the document,
        // the form, and the form control, for example:
        // document["formName'].elements["selectName "]


        if (employment_sta tus.selectedInd ex >2 &&
        employment_stat us.selectedInde x<7 && !contract_end_d ate.value){

        alert ("In order to submit the New Hire Form, you must select an end
        date for the new hires if they are contractors or temporary employees.")
        employment_stat us.focus();
        return false;
        }

        Mick

        Comment

        • Taz Lake

          #5
          Re: Javascript causes entire script to fail on web page

          Thanks to everyone for your assistance and suggestions. Apparently,
          the most obvious errors are the most difficult to troubleshoot ;-)

          I'm using Firebird instead of something like IE which will provide you
          with JavaScript notifications in a pop-up window. I just typed
          "javascript :" in the browser window and it reported the error (just
          like Netscape, duh).

          Thanks,
          Taz

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: Javascript causes entire script to fail on web page

            Taz Lake wrote:[color=blue]
            > I'm using Firebird instead of something like IE which will provide you
            > with JavaScript notifications in a pop-up window. I just typed
            > "javascript :" in the browser window and it reported the error (just
            > like Netscape, duh).[/color]

            The Web Developer Extension will not only install helpful bookmarklets
            accessible via a toolbar but also show an icon in that toolbar to
            indicate if script errors/warnings have occurred. You can always
            click the icon to display the JavaScript console. Available for
            Mozilla/5.0 Seamonkey and Firefox.

            <http://chrispederick.m yacen.com/work/firefox/webdeveloper/download/>


            HTH

            PointedEars

            Comment

            Working...