Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Safari parse error has me stumped

Reply
Thread Tools

Safari parse error has me stumped

 
 
Patrick Nolan
Guest
Posts: n/a
 
      12-20-2007
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[i].selected = true;
}
 
Reply With Quote
 
 
 
 
David Mark
Guest
Posts: n/a
 
      12-20-2007
On Dec 20, 1:55 pm, Patrick Nolan <(E-Mail Removed)> 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.
>
> 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.
 
Reply With Quote
 
 
 
 
Patrick Nolan
Guest
Posts: n/a
 
      12-21-2007
On 2007-12-20, David Mark <(E-Mail Removed)> wrote:
>> 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.
 
Reply With Quote
 
Patrick Nolan
Guest
Posts: n/a
 
      12-21-2007
On 2007-12-21, Patrick Nolan <(E-Mail Removed)> wrote:
> On 2007-12-20, David Mark <(E-Mail Removed)> wrote:
>>> 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.
>
>>
>> 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.


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[i] = theList[i];

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.
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      12-21-2007
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:

<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[i].selected = true;
}
}

</script>

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

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


--
Rob
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      12-21-2007
Randy Webb wrote:
> Patrick Nolan said the following on 12/20/2007 10:45 PM:

[...]
>> Line 75:
>> for (i=0; i<len; i++) copy[i] = theList[i];

>
>
> for(var i=0;i<len; i++){copy[i] = theList[i];}
>
> 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[i].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!!


--
Rob
 
Reply With Quote
 
Patrick Nolan
Guest
Posts: n/a
 
      12-26-2007
On 2007-12-21, RobG <(E-Mail Removed)> wrote:
> 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
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.
 
Reply With Quote
 
Patrick Nolan
Guest
Posts: n/a
 
      12-26-2007
On 2007-12-26, Randy Webb <(E-Mail Removed)> wrote:
> Patrick Nolan said the following on 12/25/2007 9:55 PM:
>> On 2007-12-21, RobG <(E-Mail Removed)> wrote:
>>> 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".
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      12-26-2007
Patrick Nolan wrote:
> 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: <http://validator.w3.org/>

> <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
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      12-26-2007
Patrick Nolan wrote:
> On 2007-12-21, RobG <(E-Mail Removed)> wrote:
>
>>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">
> <!--


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>


--
Rob
 
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
Perl error - uninitialized value has me stumped BradK Perl 0 04-10-2007 07:15 PM
Laptop has me stumped WhzzKdd Computer Support 7 03-09-2007 09:17 AM
AJAX ScriptResource does not parse on Safari 1.3.2 =?Utf-8?B?VHJ1bWJh?= ASP .Net 4 02-19-2007 11:23 PM
Startup Config has me stumped james.a.bailey@gmail.com Cisco 5 10-31-2005 08:00 PM
Stumped w/ vague com exception error -- "Error 0x80004005 occurred." Bill Youngman ASP .Net Security 1 10-11-2005 03:51 PM



Advertisments