Safari parse error has me stumped

P

Patrick Nolan

I've been developing a web page at work, testing it with Windows
Firefox and IE. Last night I tried it on my Mac at home, which
has four different browsers. Firefox and Camino worked just
fine. Mac IE had problems, but I have decided to ignore that
for a while. There were big troubles with Safari 1.3.2.

Basically none of my event handlers would work. They all got
the error message "does not allow calls". After some
googling I saw that this probably comes from a parse error
in one function. I've stared at the function and even changed
a few things, but I can't figure out what's wrong.

Here's the function, with the location of the parse error
indicated:
function submitIt() {
var title = document.forms[0].title.value;
if (title == "New title" || title == "") {
alert("You must specify a title.");
return false;
}
if (document.forms[0].authorx.length == 0) {
alert("You must specify at least one contact author.");
return(false);
}
if (document.forms[0].scigroup.value == "none") {
alert("You must choose one of the Science Groups.");
return(false);
}
selectAll(document.forms[0].authorx);
selectAll(document.forms[0].reviewersx); // Error here
selectAll(document.forms[0].eligibles);
return(true);
}

I thought it might have something to do with a reserved word,
so I changed the original "author, reviewers" to "authorx,
reviewersx". No luck.

This function is the onSubmit event handler for my form.
The elements authorx, reviewersx and eligibles are all
Select elements. The function selectAll looks like this:
function selectAll(theSelect) {
var i;
for (i=0; i<theSelect.length; i++)
theSelect.options.selected = true;
}
 
D

David Mark

I've been developing a web page at work, testing it with Windows
Firefox and IE. Last night I tried it on my Mac at home, which
has four different browsers. Firefox and Camino worked just
fine. Mac IE had problems, but I have decided to ignore that
for a while. There were big troubles with Safari 1.3.2.

Basically none of my event handlers would work. They all got
the error message "does not allow calls". After some
googling I saw that this probably comes from a parse error
in one function. I've stared at the function and even changed
a few things, but I can't figure out what's wrong.

Here's the function, with the location of the parse error
indicated:
function submitIt() {
var title = document.forms[0].title.value;
if (title == "New title" || title == "") {
alert("You must specify a title.");
return false;
}
if (document.forms[0].authorx.length == 0) {
alert("You must specify at least one contact author.");
return(false);

Lose the parenthesis. This may or may not be related to your
problem. I don't know anything about Safari 1.3.
}
if (document.forms[0].scigroup.value == "none") {
alert("You must choose one of the Science Groups.");
return(false);
Same.

}
selectAll(document.forms[0].authorx);
selectAll(document.forms[0].reviewersx); // Error here

What makes you think that line is throwing an error?
selectAll(document.forms[0].eligibles);
return(true);

See above.
}

I thought it might have something to do with a reserved word,
so I changed the original "author, reviewers" to "authorx,
reviewersx". No luck.

They aren't reserved words.
 
P

Patrick Nolan

if (document.forms[0].authorx.length == 0) {
alert("You must specify at least one contact author.");
return(false);

Lose the parenthesis. This may or may not be related to your
problem. I don't know anything about Safari 1.3.
I'll try that tonight.
What makes you think that line is throwing an error?
I brought up the javascript console window. It shows all the
error messages. When I click on the "parse error" message,
the "source code" of my web page appears with that line
highlighted.
 
P

Patrick Nolan

if (document.forms[0].authorx.length == 0) {
alert("You must specify at least one contact author.");
return(false);

Lose the parenthesis. This may or may not be related to your
problem. I don't know anything about Safari 1.3.
I'll try that tonight.

That didn't help.
I brought up the javascript console window. It shows all the
error messages. When I click on the "parse error" message,
the "source code" of my web page appears with that line
highlighted.

Oops. That seems to be unreliable. The error moved to a different
line. In fact, as I click the Refresh button repeatedly, the line
with the parse error alternates between 75 and 167.

Line 75:
for (i=0; i<len; i++) copy = theList;

Line 167:
if (document.forms[0].scigroup.value == "none") {

Now this is a real mystery! I have a couple of hundred lines
of Javascript, only Safari finds a parse error, and it won't
tell me where it is. This could turn into a long project.

By the way, I wondered if "copy" in line 75 might be a reserved
word. I changed it to xcopy, and it didn't help.
 
R

RobG

Patrick said:
I've been developing a web page at work, testing it with Windows
Firefox and IE. Last night I tried it on my Mac at home, which
has four different browsers. Firefox and Camino worked just
fine. Mac IE had problems, but I have decided to ignore that
for a while. There were big troubles with Safari 1.3.2.

Can you post a minimal example that displays the error? The following
works fine on Safari 1.0.3:

<title>Select test</title>

<script type="text/javascript">

function selectAll(id) {
var el = document.getElementById(id);
for (var i=0, len=el.length; i<len; i++) {
el.selected = true;
}
}

</script>

<div>
<input type="button" value="select all"
onclick="selectAll('sel0');">

<select multiple id="sel0">
<option>fred
<option>sally
</select>
</div>
 
R

RobG

Randy said:
Patrick Nolan said the following on 12/20/2007 10:45 PM: [...]
Line 75:
for (i=0; i<len; i++) copy = theList;



for(var i=0;i<len; i++){copy = theList;}

Safari may, or may not, be balking on the lack of the optional brackets.


I don't think that's it. I tried:

for (var i=0, len=el.length; i<len; i++) el.selected = true;

in Safari 1.0.3 and it worked fine - maybe 1.3 was a backward step? :)

Oh, I booted Mac OS X 10.2 to get back to Safari 1.x and the Google Groups
reply button doesn't work at all - I get "(event handler):Undefined value".

The OP better be quick - my old G3 makes a bit of noise and I'm not going
to leave it turned on much longer!!
 
P

Patrick Nolan

Can you post a minimal example that displays the error? The following
works fine on Safari 1.0.3:
I'm sorry it took a few days to get back to this. I applied the divide
and conquer method to the script and boiled it down to a few lines
where the syntax error occurs reliably. Here it is:

<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
function changeBox() {
// var stat = document.forms[0].status.value;
// var person = document.forms[0].pubbd.value;
var stat, person;
if ((stat == "accepted" || stat == "published") && person > 0)
{document.forms[0].public.disabled = false;} // error here
else {
document.forms[0].public.disabled = true;
document.forms[0].public.checked = false;
}
}
//-->
</script>
</head>
<body>
</body></html>

I tried a couple of variations, to no effect. The original version
didn't have {} around the line with the error. The original declarations
of "stat" and "person" are commented out, since they refer to bits of
the document not defined here; that makes no difference. In the full
web page "status", "pubbd", and "public" are form elements.
 
P

Patrick Nolan

Patrick Nolan said the following on 12/25/2007 9:55 PM:
Patrick Nolan wrote:
I've been developing a web page at work, testing it with Windows
Firefox and IE. Last night I tried it on my Mac at home, which
has four different browsers. Firefox and Camino worked just
fine. Mac IE had problems, but I have decided to ignore that
for a while. There were big troubles with Safari 1.3.2.
Can you post a minimal example that displays the error? The following
works fine on Safari 1.0.3:
I'm sorry it took a few days to get back to this. I applied the divide
and conquer method to the script and boiled it down to a few lines
where the syntax error occurs reliably. Here it is:

<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
function changeBox() {
// var stat = document.forms[0].status.value;
// var person = document.forms[0].pubbd.value;
var stat, person;
if ((stat == "accepted" || stat == "published") && person > 0)
{document.forms[0].public.disabled = false;} // error here

If Safari, or any browser for that matter, ever executes that line at
all - based on the script code you posted - then you have a severely
broken browser that shouldn't be on the web. The reason I say that? As
you have it posted, 'stat' and 'person', at the time you test them, are
both 'undefined'. When it compares stat to "accepted", it is false. The
comparison to "published" is never evaluated. Nor is the comparison of
person to 0 ever evaluated. And thus the line with the error should
never be executed.

Conclusion? There is something else in your code you aren't posting.
As I said, it's a syntax error. Even I know that this code isn't executable.
I would never try to execute it. It throws a parse error when the browser
loads it. There are hundreds of other lines in the script, equally
incomplete without this piece, and there are no parse errors when other
portions are loaded by themselves. That's what I mean by "divide and
conquer".
 
T

Thomas 'PointedEars' Lahn

Patrick said:
I'm sorry it took a few days to get back to this. I applied the divide
and conquer method to the script and boiled it down to a few lines
where the syntax error occurs reliably. Here it is:

<html>

Start with using valid markup: said:
<head>
<script language="JavaScript" type="text/javascript">

The `language' attribute is deprecated, and can be syntactically invalid.

This has never been necessary, and it is error-prone. Remove it.
function changeBox() {
// var stat = document.forms[0].status.value;
// var person = document.forms[0].pubbd.value;

If these lines serve no purpose, you should remove them to see if they are
part of the problem.
var stat, person;
if ((stat == "accepted" || stat == "published") && person > 0)
{document.forms[0].public.disabled = false;} // error here

If that line causes a syntax error, then the script engine you are using is
severely broken. However, you might be able to work around that quirk if
you include a newline after the `{' and before the `}'. My assumption is
that the script engine you are using recognizes this as an object literal
instead of a block statement and does not like the `=' that would not belong
there, then.

If that does not help, you are definitely using code that you are not showing.
else {
document.forms[0].public.disabled = true;
document.forms[0].public.checked = false;

It might be necessary to try XHTML values if boolean values do not work.
}
}
//-->

Remove that line as well.


HTH

PointedEars
 
R

RobG

Patrick said:
I'm sorry it took a few days to get back to this. I applied the divide
and conquer method to the script and boiled it down to a few lines
where the syntax error occurs reliably. Here it is:

<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--

Note what Thomas said about the language attribute and comment delimiters. :)
function changeBox() {
// var stat = document.forms[0].status.value;
// var person = document.forms[0].pubbd.value;
var stat, person;
if ((stat == "accepted" || stat == "published") && person > 0)
{document.forms[0].public.disabled = false;} // error here

Yup, old Safari (at least version 1.0.3) doesn't like that syntax for
accessing form controls when used on the left-hand side of an assignment,
althought it is OK with it used on the right hand side hence no error with
the initialisation of stat and person. Go figure.

Use:

document.forms[0].elements['public'].disabled = false;

And use the same syntax everyhwere.

I would use a name for the form too rather than use the index, but that's
just personal preference. My test case:

<title>Old Safari form test</title>
<script type="text/javascript">


function changeBox() {
var stat = document.forms[0].status.value;
var person = document.forms[0].pubbd.value;
var stat, person;

if ((stat == "accepted" || stat == "published") && person > 0) {

// This syntax will cause a parse error
document.forms[0].public.disabled = false;

// This doesn't
document.forms[0].elements['public'].disabled = false;
} else {
document.forms['fred'].elements['public'].disabled = true;
document.forms[0].elements['public'].checked = false;
}
}
</script>
<form name="fred" action=""><div>
<input type="text" value="published" name="status">
<input type="text" value="0" name="pubbd">

<input type="checkbox" name="public">
<input type="button" value="click me" onclick="changeBox()">
</div></form>
 
T

Thomas 'PointedEars' Lahn

RobG said:
Patrick said:
function changeBox() {
// var stat = document.forms[0].status.value;
// var person = document.forms[0].pubbd.value;
var stat, person;
if ((stat == "accepted" || stat == "published") && person > 0)
{document.forms[0].public.disabled = false;} // error here

Yup, old Safari (at least version 1.0.3) doesn't like that syntax for
accessing form controls when used on the left-hand side of an assignment,
althought it is OK with it used on the right hand side hence no error with
the initialisation of stat and person. Go figure.

Use:

document.forms[0].elements['public'].disabled = false;

And use the same syntax everyhwere.

While I agree that the suggested both standards compliant and backwards
compatible referencing is to be preferred, if that worked then the OP should
not have observed a syntax error as stated but a runtime error (probably a
ReferenceError exception) instead. Because this piece of code is
syntactically *correct*, and a SyntaxError exception should only be thrown
if the mere compilation of the code failed, which would happen before it is
executed. Unless, of course, Safari 1.0.3's script engine would not be
ECMAScript-compliant at all.


PointedEars
 

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,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top