Javascript causes entire script to fail on web page

Discussion in 'Javascript' started by Taz Lake, Jul 6, 2004.

  1. Taz Lake

    Taz Lake Guest

    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_status.selectedIndex == 3 ||
    employment_status.selectedIndex == 4 ||
    employment_status.selectedIndex == 5 ||
    employment_status.selectedIndex == 6) && (contract_end_date.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_status.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
    Taz Lake, Jul 6, 2004
    #1
    1. Advertising

  2. Taz Lake

    Lee Guest

    Taz Lake said:
    >
    >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_status.selectedIndex == 3 ||
    >employment_status.selectedIndex == 4 ||
    >employment_status.selectedIndex == 5 ||
    >employment_status.selectedIndex == 6) && (contract_end_date.value ==
    >"")


    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.
    Lee, Jul 6, 2004
    #2
    1. Advertising

  3. (Taz Lake) writes:

    I assume "employment_status" is a declared variable that points to
    a select element.

    > if (employment_status.selectedIndex == 3 ||

    ^ parenthesis begin

    > employment_status.selectedIndex == 4 ||
    > employment_status.selectedIndex == 5 ||
    > employment_status.selectedIndex == 6) && (contract_end_date.value ==

    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 -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Jul 6, 2004
    #3
  4. Taz Lake

    Mick White Guest

    Taz Lake wrote:

    > 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_status.selectedIndex == 3 ||
    > employment_status.selectedIndex == 4 ||
    > employment_status.selectedIndex == 5 ||
    > employment_status.selectedIndex == 6) && (contract_end_date.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_status.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


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


    if (employment_status.selectedIndex >2 &&
    employment_status.selectedIndex<7 && !contract_end_date.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_status.focus();
    return false;
    }

    Mick
    Mick White, Jul 6, 2004
    #4
  5. Taz Lake

    Taz Lake Guest

    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
    Taz Lake, Jul 7, 2004
    #5
  6. Taz Lake wrote:
    > 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).


    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.myacen.com/work/firefox/webdeveloper/download/>


    HTH

    PointedEars
    Thomas 'PointedEars' Lahn, Jul 11, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo
    Replies:
    0
    Views:
    518
    S. Justin Gengo
    Jul 16, 2003
  2. Replies:
    0
    Views:
    394
  3. Wenjie

    if (f() != FAIL) or if (FAIL != f())?

    Wenjie, Jul 28, 2003, in forum: C Programming
    Replies:
    3
    Views:
    440
    E. Robert Tisdale
    Jul 31, 2003
  4. jason9364
    Replies:
    0
    Views:
    850
    jason9364
    Nov 19, 2007
  5. Karl A Mikesell

    Screened Subnet (DMZ) causes Web Service to fail

    Karl A Mikesell, May 7, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    138
    Jian Bo
    May 8, 2004
Loading...

Share This Page