Safari parse error has me stumped

Discussion in 'Javascript' started by Patrick Nolan, Dec 20, 2007.

  1. 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;
    }
    Patrick Nolan, Dec 20, 2007
    #1
    1. Advertising

  2. Patrick Nolan

    David Mark Guest

    On Dec 20, 1: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.
    >
    > 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.
    David Mark, Dec 20, 2007
    #2
    1. Advertising

  3. On 2007-12-20, David Mark <> 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.
    Patrick Nolan, Dec 21, 2007
    #3
  4. On 2007-12-21, Patrick Nolan <> wrote:
    > On 2007-12-20, David Mark <> 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 = 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.
    Patrick Nolan, Dec 21, 2007
    #4
  5. Patrick Nolan

    RobG Guest

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

    </script>

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

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


    --
    Rob
    RobG, Dec 21, 2007
    #5
  6. Patrick Nolan

    RobG Guest

    Randy Webb wrote:
    > 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!!


    --
    Rob
    RobG, Dec 21, 2007
    #6
  7. On 2007-12-21, RobG <> 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.
    Patrick Nolan, Dec 26, 2007
    #7
  8. On 2007-12-26, Randy Webb <> wrote:
    > Patrick Nolan said the following on 12/25/2007 9:55 PM:
    >> On 2007-12-21, RobG <> 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".
    Patrick Nolan, Dec 26, 2007
    #8
  9. 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
    Thomas 'PointedEars' Lahn, Dec 26, 2007
    #9
  10. Patrick Nolan

    RobG Guest

    Patrick Nolan wrote:
    > On 2007-12-21, RobG <> 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
    RobG, Dec 26, 2007
    #10
  11. RobG wrote:
    > Patrick Nolan wrote:
    >> 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
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
    Thomas 'PointedEars' Lahn, Dec 27, 2007
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Ross

    General Network Error - MS Stumped

    Joe Ross, Feb 26, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    549
    Joe Ross
    Mar 1, 2004
  2. =?Utf-8?B?VHJ1bWJh?=

    AJAX ScriptResource does not parse on Safari 1.3.2

    =?Utf-8?B?VHJ1bWJh?=, Feb 15, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    512
    =?Utf-8?B?VHJ1bWJh?=
    Feb 19, 2007
  3. BradK
    Replies:
    0
    Views:
    3,047
    BradK
    Apr 10, 2007
  4. Bill Youngman
    Replies:
    1
    Views:
    185
    Bill Youngman
    Oct 11, 2005
  5. VUNETdotUS

    Parse XML in Safari?

    VUNETdotUS, Dec 5, 2007, in forum: Javascript
    Replies:
    7
    Views:
    204
    Thomas 'PointedEars' Lahn
    Dec 7, 2007
Loading...

Share This Page