PDA

View Full Version : Syntax Error problem not activating javascript function



MarkSinclair
04-01-2006, 06:24 AM
I've been staring at this for a few hours and I am going mad. I am getting an error in Internet Explorer saying that there is a Syntax Error at Line: 52, Char: 34, but there is only 32 characters in the line. The offending line and lines around it are (I have added line numbers for clarity):

47 <html>
48
49 <head>
50 <script language = "JavaScript">
51
52 function frmShiftInfo_onsubmit()
53 {
54 alert("in frmShiftInfo");
55 var form = document.frmShiftInfo;

I had added line 54 in to see it was reaching the function; it wasn't. I am using this to call it:

<form action="UpdateHead.asp" method="post" name="frmShiftInfo" onsubmit="return frmShiftInfo_onsubmit()">

It had been working and I am unsure what has changed. On the same page is an onchange function, it is no longer working. The odd thing is that other page's javascript functions work with very similar code, so I am perplexed.

Any ideas?

Thanks,
Mark.

djr33
04-01-2006, 08:07 AM
Idea, but not a definite answer... just a random guess.

Since JS functions use () and get stuff from the page input into those...

what if it is seeing the line as longer, like function frmShiftInfo_onsubmit(whateverwasputinheresothisislongnow)

that would give you enough characters...

Or... maybe its a more general problem.... a loop error, or a dead end, or something. php gives odd errors when this happens and its something you just gotta know... it won't tell you if you've got a bad loop, etc. Maybe something like that....

sorry I can't help more.



Note: I'm taking a stab in the dark with the above guess. Someone will probably correct me (if I'm wrong), so don't worry if what I'm saying doesn't help... just a random guess.

MarkSinclair
04-01-2006, 09:17 AM
Thanks, but I don't think it is that.

The when the function is called there aren't any variables in the brackets; unless javascript puts stuff in there that is not visible (I was unaware it did). Good idea about the characters though.

Re: loops. There aren't loops in around the start or end of the form, although there are ASP driven loop wholly inside the form (but they would have done their work before the function is activated). Also, there aren't any loops in the functions; just if statements.

Not sure about the dead end though. There is only one path through the pages because the design requires it.

Thanks for your ideas,
Mark.

.alias.
04-01-2006, 10:14 AM
I might be something to do with

onsubmit="return frmShiftInfo_onsubmit()">

IE is strange it might be "return" causing the error, proberly not but give it a shot

Twey
04-01-2006, 12:01 PM
No.
Most likely, it's line 55:
var form = document.frmShiftInfo;Try:
var form = document.forms['frmShiftInfo'];

MarkSinclair
04-01-2006, 10:05 PM
Thanks for everyone's help, but this comes down to stupidity, lack of oxygen and lack of sleep.

IE was saying there was an error at line 52, I forgot that it only sees the HTML. So line 52 was actually line 97 (the problem was in a completely different function), because there is 45 lines of ASP at the start, oops.

Amazing what a bit of sleep will do. Next time I will rest before panicking.

Thanks again,
Mark.

(By-the-way, the problem was pretty simple. I had some big if statements with a lot of ||, I forgot to put () around each item.)

Twey
04-01-2006, 10:14 PM
Heh, whoops. :p
But you still ought to use the document.forms collection.