Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104

    JS/PHP Parse Error

    Jesus, I should change my name to Mr. Parse Error. Or something to that effect. My scripts always SEEM like they should work.. Maybe I shouldn't mix JS and PHP how I do.. it's so convenient though. Sort of.

    Here's my script. It's suppose to show a few wallpaper buttons w/ links to resolutions, on a page called wallpapers.php. When you click the resolution, a function produces links in that space that specificy OS. When you click the desired OS, you get linked to a page that's something like wallpapers.php?wall=t&pic=GTF&res=1024x768&sys=M (though it might not be in that order, I forget) where $wall specifies that it's not the original wallpaper.php and the rest were derived from the order of links you took from the page. Note that the missing body, head, and html tags are in the include files. And don't worry, I'm getting rid of the sticker joke. Soon.

    Code:
    <html>
    <head>
    <title>CGP Wallpapers</title>
    <META name="keywords" data="wall,paper,back,ground,pic,image,background"> 
    <META name="description" data="Want your comp to look stylish?  Set some of our wallpapers as your computer's background image.  Or get some stickers... :-D">
    <script language="javascript">
    <!-- 
    
    function clickRes(pic,res) {
     if (res="BIG") {
      res="1024x768"; }
     if (res="SMA") {
      res="800x600"; }
     var spanId="link"+pic;
     span=document.getElementById(spanId);
     span.innerHTML="<a href='wallpapers.php?wall=t&pic="+pic+"&sys=W$res="+res'>Windows</a> - <a href=a href='wallpapers.php?wall=t&pic="+pic+"&sys=M$res="+res'>Mac</a> - <a href='javascript:clickBack("+pic+")'>BACK</a>";
     }
    
    function clickBack(pic) {
     resOne="BIG";
     resTwo="SMA";
     var spanId="link"+pic;
     span=document.getElementById(spanId);
     span.innerHTML="<a href='javascript("+pic+","+resOne+")'>1024x768</a> - <a href='javascript("+pic+","+resTwo+")'>800x600</a>";
     }
    
    // -->
    </script>
    
    <?php include("(server path here)/Includes/UpperFormat1.inc"); ?>
    <img src="/Media/Images/BA3Wallpapers.jpg" border="0" style="POSITION: ABSOLUTE; TOP: 181; LEFT: 265" />
    <span style="WIDTH: 498; HEIGHT: 400; OVERFLOW: AUTO; MAXWIDTH: 498">
    <!-- TEXTAREA BEGIN -->
    
    <?php
    
    if (isSet($wall)) {
    
    if ($pic == "GMC")
     $pic = "GameCube";
    elseif ($pic == "Mac")
     $pic = "SSX Mac";
    elseif ($pic == "GTF")
     $pic = "GT Falco";
    
    if (sys == "W")
     $sysprint = "Win";
     $systext = "TEXT HERE";
    if (sys == "M")
     $sysprint = "Mac";
     $sysprint = "TEXT HERE";
    
    
    $header = ": " . $pic . " (" . $sysprint . ", " . $res . ")";
    }
    else 
    $header = "";
    
    ?>
    
    <h3><center>CGP Wallpapers<?php print($header); ?></center></h3>
    
    <?php 
    if (!isSet($wall)) {
    ?>
    Here, you can find wallpapers for your computer.  Click on the resolution you want, and then the platform.<br /><br />
    <noscript>The wallpapers section of CGP uses JavaScript to function, and your browser doesn't implement it.  You can still see the wallpapers, though, so if you want one,
     <a href="mailto:[email protected]">email Falconix</a> with the screen resolution and platform you require.<br /><br /></noscript>
    <table width="100%" border="0" cellpadding="10" cellspacing="0">
    <!-- EDIT WHEN ADDING WALLPAPERS -->
     <tr>
      <td width="50%" align="center">
       <img src="/Media/Images/wallpapers/BGPicGMCButton.jpg" border="0" /><br />
       <span ID="linkGMC"><a href='javascript:clickRes("GMC","BIG")'>1024x768</a> - <a href='javascript:clickRes("GMC","SMA")'>800x600</a></span>
      </td>
      <td width="50%" align="center">
       <img src="/Media/Images/wallpapers/BGPicMacButton.jpg" border="0" /><br />
       <span ID="linkMac"><a href='javascript:clickRes("Mac","BIG")'>1024x768</a> - <a href='javascript:clickRes("Mac","SMA")'>800x600</a></span>
      </td>
     </tr>
     <tr>
      <td width="50%" align="center">
       <img src="/Media/Images/wallpapers/BGPicGTFButton.jpg" border="0" /><br />
       <span ID="linkGTF"><a href='javascript:clickRes("GTF","BIG")'>1024x768</a> - <a href='javascript:clickRes("GTF","SMA")'>800x600</a></span>
      </td>
     </tr>
    <!-- END EDIT SECTION -->
    </table>
    
    <?php 
    }
    else
    {
    ?>
    This page is coming soon!
    <?php
    }
    ?>
    <!-- TEXTAREA END -->
    </span>
    <?php include("(server path here)/Includes/LowerFormat1.inc"); ?>
    You can see crap in action at www.cgplatinum.com/wallpapers.php

    First, I get an error saying I'm missing a semicolon, but they all seem to be there. Even the one it says I'm missing..

    When you click on a link, you get an error on line 1, "object expected". I'm sure SOMEONE has had this before... What is it?

    Other than that, no progress can be made through the links until the object error is dealt with.

    Any suggestions? I welcome EVERYTHING... really.

    Sorry about the post width!
    :-D

  2. #2
    Join Date
    Jan 2002
    Posts
    360
    Why do you need the javascript?

  3. #3
    Join Date
    Aug 2000
    Location
    Redmond, WA
    Posts
    310
    Why do you comment out the closing HTML comment tag but not the opening one? Especially if you're getting a parse error on line 1, that would be the first place I'd look. Try changing '<!--' to '//<!--'. That should tell the java script parser to ignore the opening of the HTML comment. I hope this helps.
    Chris Spangler
    [email protected]

  4. #4
    Join Date
    Sep 2002
    Location
    San Francisco, CA
    Posts
    103
    Originally posted by banner
    Why do you comment out the closing HTML comment tag but not the opening one?
    the <!-- and --> around javascript are to hide it from browsers that dont support javascript

    the // before the closing comment tag is recommended for netscape 4.7 compatibility

  5. #5
    Join Date
    Aug 2000
    Location
    Redmond, WA
    Posts
    310
    Ok, second guess, try placing a ';' at the end of the call to clickRes. I've had problems with that in the past. I also noticed one other logic error in your code. It currently says:
    Code:
    function clickRes(pic,res) {
     if (res="BIG") {
      res="1024x768"; }
     if (res="SMA") {
      res="800x600"; }
     ...
    It should probably say:
    Code:
    function clickRes(pic,res) {
     if (res=="BIG") {
      res="1024x768"; }
     if (res="SMA") {
      res="800x600"; }
     ...
    In your version, it sets res to "BIG" or "SMA" (which should always be true) and so res always ends up being 800x600 when passed on in the link. I hope this helps.

    EDIT: Or maybe it's not needed at the end of the calls to clickRes. It probably wouldn't hurt to try it though.
    Last edited by banner; 09-28-2002 at 11:18 PM.
    Chris Spangler
    [email protected]

  6. #6
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104
    I need the JavaScript to have the user specificy two things by clicking on two links, in succession.

    I've:

    -changed the comparison operators to ==
    -put semicolons on all of the calls to clickRes
    -Added the calls to clickBack from click res; previously, I only had "javascript(pic)" or something along those lines
    -Added semicolons to the clickBack calls

    But I still get all of the same errors. What's wrong??
    :-D

  7. #7
    Join Date
    Jan 2002
    Posts
    360
    i still wonder specifically what you need the javascript for. i guess i just havent taken the time to get my head around this one

  8. #8
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104
    Does anyone see the problem? The object thing seems to be precendent, but I don't understand it. OOP sucks...
    :-D

  9. #9
    Join Date
    Sep 2002
    Location
    San Francisco, CA
    Posts
    103
    you've got your "" and ' in a twist aswell as missing some + signs

    If you space out long lines of code like that it becomes clear

    shoud be like this, with a " and a + after the variable 'res' in your clickRes function...

    try this

    span.innerHTML="<a href='wallpapers.php?wall=t&pic="
    + pic + "&sys=W$res="
    + res + "'>Windows</a> - <a href=a href='wallpapers.php?wall=t&pic="
    + pic + "&sys=M$res="
    + res + ">Mac</a> - <a href='javascript:clickBack("
    + pic + ");'>BACK</a>";

  10. #10
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104
    OMG I wuv you!!



    Thanks a lot... that was a dumb error.
    :-D

Posting Permissions

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