Run Time Error. Expected ';'

Discussion in 'Javascript' started by andy.herrera@gmail.com, Jul 26, 2005.

  1. Guest

    I'm getting this Error Message. Expected ';'

    Please Select One:
    <form name="form1"> <<------------ Error is here.
    <select name="selectTrans" onChange="If (this.value == 'checkout')
    window.location.href='CheckOut.php';">
    <option>---Please Select One ---</option>
    <option value="checkout">Check OUT</option>
    <option value="checkin">Check IN</option>
    </select>
    </form>

    What looks wrong with the above code? I did it this way because I was
    getting the same error (Expected ';' error) with the code below....
    <head>
    <script language="JavaScript" type="text/javascript">

    function deil(ans)
    { <<<-----------------------error here
    If (ans == "checkout") {
    window.location.href="CheckOut.php";
    }
    }
    ..... more functions here...
    </script>
    </head>
    ..
    ..
    ..
    Please Select One:
    <form name="form1">
    <select name="selectTrans" onChange="HereWeGo();">
    <option>---Please Select One ---</option>
    <option value="checkout">Check OUT</option>
    <option value="checkin">Check IN</option>
    </select>
    </form>

    I've spent hours trying to figure this out and I still can't get it to
    work!!! Does anyone know what is going on? It looks good to be but
    obviously it's not.

    Thanks in advance!!! no, really :)

    Andy
    , Jul 26, 2005
    #1
    1. Advertising

  2. Lee Guest

    said:
    >
    >I'm getting this Error Message. Expected ';'
    >
    >Please Select One:
    ><form name="form1"> <<------------ Error is here.
    > <select name="selectTrans" onChange="If (this.value == 'checkout')
    >window.location.href='CheckOut.php';">


    Apparently you're using some horribly defective browser that's not
    pointing out the actual error.

    There is no builtin Javascript function named "If".
    You mean "if"
    Lee, Jul 26, 2005
    #2
    1. Advertising

  3. Re: Run Time Error. Expected ';'

    wrote:
    > I'm getting this Error Message. Expected ';'
    >
    > Please Select One:
    > <form name="form1"> <<------------ Error is here.



    The error is actually here:
    > <select name="selectTrans" onChange="If (this.value == 'checkout')
    > window.location.href='CheckOut.php';">


    You have a capital I in If.
    <select name="selectTrans" onChange="if(this.value == 'checkout')
    window.location.href='CheckOut.php';">


    [snip]
    > What looks wrong with the above code? I did it this way because I was
    > getting the same error (Expected ';' error) with the code below....
    > <head>
    > <script language="JavaScript" type="text/javascript">
    >
    > function deil(ans)
    > { <<<-----------------------error here


    Same error here: capital I in If.
    > If (ans == "checkout") {
    > window.location.href="CheckOut.php";
    > }
    > }
    > ..... more functions here...
    > </script>
    > </head>


    [snip]
    > Thanks in advance!!! no, really :)
    >
    > Andy


    Odd... I would've expected the error 'Object expected.', especially if
    it's a runtime error.

    Either way, that looks like your problem.

    For the record, anytime you have an error involving a semicolon, always
    check the lines immediately surrounding the one cited in the error.
    Just like with errors involving braces you should trace backward
    indefinitely, with semicolons trace back a line, then forward two.

    Also, I'm reliably informed that we shouldn't use the .value property
    of select boxes. I've never had a problem with it myself, but I'm told
    that compatibility is limited or unpredictable.

    Hope that helps.
    Christopher J. Hahn, Jul 26, 2005
    #3
  4. Re: Run Time Error. Expected ';'

    On 26/07/2005 06:23, Christopher J. Hahn wrote:

    > wrote:
    >
    >> I'm getting this Error Message. Expected ';'


    [snip]

    > The error is actually here:
    >
    >> <select name="selectTrans" onChange="If (this.value == 'checkout')
    >> window.location.href='CheckOut.php';">


    [snip]

    > Odd... I would've expected the error 'Object expected.', especially if
    > it's a runtime error.


    In both cases, the parser will be encountering a syntax error.

    If (...)

    will be considered a function call, with If as the identifier of that
    function. In the first case, what immediately follows is an assignment
    expression:

    A() a = b;

    which not match any grammar production. With the second case, a block
    statement follows:

    A() {}

    which is also nonsense.

    [snip]

    > Also, I'm reliably informed that we shouldn't use the .value property
    > of select boxes. I've never had a problem with it myself, but I'm
    > told that compatibility is limited or unpredictable.


    Older browsers may not support the property. NN4, for example, always
    returns null. It's briefly mentioned in the group FAQ.

    Mike

    --
    Michael Winter
    Prefix subject with [News] before replying by e-mail.
    Michael Winter, Jul 26, 2005
    #4
  5. LilAndy23 Guest

    Re: Run Time Error. Expected ';'

    Wow! I can't believe it needed to be a lowercase i in the 'if'
    statement! I wasted so many hours. Thanks so much for your help!!

    Andy
    LilAndy23, Jul 26, 2005
    #5
  6. Re: Run Time Error. Expected ';'

    Michael Winter wrote:
    > On 26/07/2005 06:23, Christopher J. Hahn wrote:
    >
    > > wrote:
    > >
    > >> I'm getting this Error Message. Expected ';'

    >
    > [snip]
    >
    > > The error is actually here:
    > >
    > >> <select name="selectTrans" onChange="If (this.value == 'checkout')
    > >> window.location.href='CheckOut.php';">

    >
    > [snip]
    >
    > > Odd... I would've expected the error 'Object expected.', especially if
    > > it's a runtime error.

    >
    > In both cases, the parser will be encountering a syntax error.
    >
    > If (...)
    >
    > will be considered a function call, with If as the identifier of that
    > function. In the first case, what immediately follows is an assignment
    > expression:
    >
    > A() a = b;


    Put that way, it makes perfect sense. Thanks for clarifying that for
    me.


    [on using .value property of select elements]
    >
    > Older browsers may not support the property. NN4, for example, always
    > returns null. It's briefly mentioned in the group FAQ.


    Again, thank you. I hadn't seen that in the FAQ (I confess to not
    having read *every* line of it).

    > Mike
    >
    > --
    > Michael Winter
    > Prefix subject with [News] before replying by e-mail.


    Good info, Mike. I appreciate it.
    Christopher J. Hahn, Jul 27, 2005
    #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. Kathy Burke
    Replies:
    2
    Views:
    430
    Kathy Burke
    Aug 1, 2003
  2. Paul Cook
    Replies:
    0
    Views:
    447
    Paul Cook
    Nov 6, 2003
  3. flamesrock
    Replies:
    8
    Views:
    449
    Hendrik van Rooyen
    Nov 24, 2006
  4. iskeletor
    Replies:
    3
    Views:
    360
    Barry Schwarz
    Dec 26, 2006
  5. Pierre Yves
    Replies:
    2
    Views:
    481
    Pierre Yves
    Jan 10, 2008
Loading...

Share This Page