By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,315 Members | 2,150 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,315 IT Pros & Developers. It's quick & easy.

Run Time Error. Expected ';'

P: n/a
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 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
an**********@gmail.com 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.

Jul 26 '05 #2

P: n/a
Lee
an**********@gmail.com 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"

Jul 26 '05 #3

P: n/a
On 26/07/2005 06:23, Christopher J. Hahn wrote:
an**********@gmail.com 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.
Jul 26 '05 #4

P: n/a
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

Jul 26 '05 #5

P: n/a
Michael Winter wrote:
On 26/07/2005 06:23, Christopher J. Hahn wrote:
an**********@gmail.com 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.

Jul 27 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.