Syntax Error

C

crjunk

Can someone show me what I am doing wrong with this function? I'm
still having problems with javascript syntax. I'm sure this is some
kindergarten mistake that I've made. IE is telling me that a semicolon
is expected at the end of the IF statement.

*NOTE: I have left out my "setFocus()" function from this post (See
Body OnLoad).

<HEAD>
<TITLE> Maintain MPR </TITLE>
<script type="text/javascript" language="JavaScript">
<!--
function SaveChangesPrompt() {
If ((document.ScheduleForm.txtRecordStatus.value) == "Changes Made -
Record Not Saved.") {
confirm("You have attempted to leave this page. If you have made
any changes to the fields without clicking the Save button, your
changes will be lost. Are you sure you want to exit this page?") ;
}
}
// -->
</script>
</HEAD>
<BODY onload='setFocus()'; onunload='SaveChangesPrompt()'>


Thanks for your patience!

Sincerely,
CR Junk
 
L

Lee

crjunk said:
Can someone show me what I am doing wrong with this function? I'm
still having problems with javascript syntax. I'm sure this is some
kindergarten mistake that I've made. IE is telling me that a semicolon
is expected at the end of the IF statement.

*NOTE: I have left out my "setFocus()" function from this post (See
Body OnLoad).

<HEAD>
<TITLE> Maintain MPR </TITLE>
<script type="text/javascript" language="JavaScript">
<!--
function SaveChangesPrompt() {
If ((document.ScheduleForm.txtRecordStatus.value) == "Changes Made -
Record Not Saved.") {
confirm("You have attempted to leave this page. If you have made
any changes to the fields without clicking the Save button, your
changes will be lost. Are you sure you want to exit this page?") ;
}
}
// -->
</script>

The syntax error is the word "If". It should be "if".
Also, you don't need the language attribute in the script tag and
you don't need the lines;
<!--
or
// -->
 
W

web.dev

Hi CR,
If ((document ...[snip]

Lowercase "if".

Your semicolon in this line is placed outside of the quotes when it
should be inside.

<body onnload = "setFocus();" onunload = "SaveChangesPrompt();">

Hopefully this will eliminate the error message you're getting.
 
C

crjunk

Lowercase "if".

Thanks! I didn't realize that is is case sensitive.
should be inside.

That was a dumb mistake on my part.

Thanks again for your help!

Sincerely,
CR Junk
 
I

Ivan Marsh

Thanks! I didn't realize that is is case sensitive.

should be inside.

That was a dumb mistake on my part.

Dumb mistakes are quite common when programming.
I can't tell you how many hours I've spent debugging the classic fubar:

if (x = y)
 
D

Douglas Crockford

That was a dumb mistake on my part.
Dumb mistakes are quite common when programming.
I can't tell you how many hours I've spent debugging the classic fubar:

if (x = y)

JSLint can be very effective at finding those sorts of problems.

http://www.JSLint.com
 
C

crjunk

JSLint can be very effective at finding those sorts of problems.

Thanks for referring me to JSLint. It's very helpful.

CR Junk
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top