SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Expected error ')' on web page

    This is the script I am using

    Code:
      <script language="JavaScript">
    <!--
    width=screen.width;
    
    if(width<1024)
      table_width="98%";
    else if(width<1152)
      table_width="96%";
    else if(width<1280)
      table_width="94%";
    else if(width<1600)
      table_width="92%";
    else
      table_width="88%";
    
    //-->
      </script>
    
    <script language="javascript">document.write("<div style=\"width: "+table_width+";\">")</script>
    Keeps on giving me error expeted ')'

    Can some suggest or help please

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,156
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    quotes

    Quotes can be tricky. You need to use a combination of single ' and double ", or make sure you write them as entities &#38;#34; or escape \ them.
    Code:
    <script language="javascript">document.write("<div style=\"width: "+table_width+";\">")</script>
    my guess is that somewhere in there the script thinks a quote is ending the argument. Maybe try mixing single quotes in?
    BTW do you really intend for screen widths greater than/equal to 1024 to set table_width to 88% ?

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tried

    with both of your suggestions

    <script language="javascript">document.write("<div style=\"width: "+table_width+";\">"); </script>

    second alternative

    <script language="javascript">document.write(\"<div style=\"width: "+table_width+";\">\"); </script>

    and

    <script language="javascript">document.write('<div style=\"width: "+table_width+";\">'); </script>

    either don't work

    Playing with the settings.... this may be final

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    width=screen.width;
    
    if(width<1024)
      table_width="98%";
    else if(width<1152)
      table_width="96%";
    else if(width<1280)
      table_width="92%";
    else if(width<1600)
      table_width="80%";
    else
      table_width="70%";
      
    //-->
    </script>
    Any other suggestions or ideas how this can be done?

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,156
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    error?

    I just tried the script in your first post. It didn't throw any errors. Are you sure you tested the same script when you got the "expected )" error msg?
    HTML Code:
    <html><head>
    <script language="JavaScript">
    <!--
    width=screen.width;
    
    if(width<1024)
      table_width="98%";
    else if(width<1152)
      table_width="96%";
    else if(width<1280)
      table_width="94%";
    else if(width<1600)
      table_width="92%";
    else
      table_width="88%";
    
    //-->
      </script>
    
    <script language="javascript">document.write("<div style=\"width: "+table_width+";border: 1px solid #f00;\">test div</div>")</script>
    </head>
    <body></body></html>

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the page where you can see the error

    http://www.indian-town.com/refer/

    error message

    "A runtime Error has occured. Do you wish to Debug?"

    Line: 171
    Error: Expected ')'

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,156
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    syntax error

    The Opera error console shows
    width: "+table_width+";">");
    the third " is missing a \

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried adding \" but did not work either.

    Looking in Netscape Javascript console shows

    Error: missing ) after argument list
    Source File: http://www.indian-town.com/refer/
    Line: 172, Column: 28
    Source Code:
    document.write("<div style="width: "+table_width+";">");

    Code:
    <script language="javascript">document.write("<div style=\"width: "+table_width+";\">"); </script>

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Simplest fix would be to use apostrophes instead of quotes for the Javascript document.write and keep the quotes for the HTML that it is writing like this:

    document.write('<div style="width: '+table_width+';">';
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  9. #9
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks felgall.... it worked


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •