Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Run Time Error. Expected ';'

Reply
Thread Tools

Run Time Error. Expected ';'

 
 
andy.herrera@gmail.com
Guest
Posts: n/a
 
      07-26-2005
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

 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      07-26-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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"

 
Reply With Quote
 
 
 
 
Christopher J. Hahn
Guest
Posts: n/a
 
      07-26-2005
(E-Mail Removed) 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.

 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      07-26-2005
On 26/07/2005 06:23, Christopher J. Hahn wrote:

> (E-Mail Removed) 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.
 
Reply With Quote
 
LilAndy23
Guest
Posts: n/a
 
      07-26-2005
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

 
Reply With Quote
 
Christopher J. Hahn
Guest
Posts: n/a
 
      07-27-2005
Michael Winter wrote:
> On 26/07/2005 06:23, Christopher J. Hahn wrote:
>
> > (E-Mail Removed) 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time template list definition / Run-time variable type definition Pierre Yves C++ 2 01-10-2008 02:52 PM
Is time.time() < time.time() always true? flamesrock Python 8 11-24-2006 06:51 AM
Unlikely differences between design time and run time. Tzury Bar Yochay ASP .Net 3 11-29-2003 08:56 AM
Determining control behaviour at design-time/run-time Paul Cook ASP .Net 0 11-06-2003 09:17 AM
Run sub procedure -- "expression expected" ??? Kathy Burke ASP .Net 2 08-01-2003 07:03 AM



Advertisments