www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] rollover image include file

  1. #1
    Join Date
    Jul 2010
    Location
    Birmingham, UK
    Posts
    67

    resolved [RESOLVED] rollover image include file

    i just reworked my site so that now each page is almost entirely comprised of style sheets and include files. pretty cool and organized.

    the only niggling problem i have now, after sorting out all the syntazx errors caused by quoatations, etc, is that the mouse rollover function in one of the files does not work. the link still works and the "off" image displays, but the image will not change on mouseover. and if i simply replace the original code, it works fine.

    here is the code in the include (should be pretty straight-forward non-php stuff):

    Code:
    <?php echo '
    
    <a href="http://www.jamesmehaffey.com/pages/webcam/webcam.html"
    	onmouseover=\'image1.src="http://www.jamesmehaffey.com/images/webcam/hummingbird-on01.png\';"
    	onmouseout=\'image1.src="http://www.jamesmehaffey.com/images/webcam/hummingbird-off01.png\';">
    			
    	<img name="image1" src="http://www.jamesmehaffey.com/images/webcam/hummingbird-off01.png" alt="Hummingbird" width="50" height="58" border="0" /></a>
    
    '; ?>

    i'm not getting any errors or anything that would point to the source of the problem, so i'm a bit stuck. it's not a big deal, but it would be useful to know for future reference.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,615
    Looks to me like you have your single- and double-quotes reversed at the end of the two onmouseover lines.

    On a side note: since it appears there are no PHP variables/functions within all that text, why not just exit out of PHP mode at that point instead of doing a big echo?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jul 2010
    Location
    Birmingham, UK
    Posts
    67
    well spotted, nogdog. that's what i get for staring at the screen for so long... it's almost always something stupid like that.

    to answer your question though, this is just a snippet of code that appears on every page. so i just created this simple echo and put it in an include file.

    thanks.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,615
    Quote Originally Posted by mimewear View Post
    well spotted, nogdog. that's what i get for staring at the screen for so long... it's almost always something stupid like that.

    to answer your question though, this is just a snippet of code that appears on every page. so i just created this simple echo and put it in an include file.

    thanks.
    Even as a PHP include file, it does not have to be PHP code. Both of these files would give the same functional result if included into a PHP script:

    foo.php
    PHP Code:
    <?php
    echo "<p>This is a test.</p>\n";
    ?>
    bar.php:
    Code:
    <p>This is a test.</p>
    index.php:
    PHP Code:
    <?php
    include 'foo.php';
    include 
    'bar.php';
    ?>
    Output of index.php would be:
    This is a test.
    This is a test.
    It's not a big deal, but it saves you some typing and escaping of quotes, and may process just a tad faster. It's also probably a bit easier to debug. If you do need to echo large chunks of HTML, you might consider using the "heredoc" syntax, which makes the quoting a bit simpler, since the string itself is not quoted in the usual way:
    PHP Code:
    <?php
    echo <<<END
    <p onclick="foo('bar');">This is a test.</p>
    <p onclick="bar('foo');">It is only a test.</p>
    END;

    /* the "END;" must not have any white-space before it */
    ?>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jul 2010
    Location
    Birmingham, UK
    Posts
    67
    sorry, i misunderstood you. a perfect example of why it's important to take breaks and sleep sometimes. yeah, i see what you mean - that makes life a little easier. still though, it was a good if pointless exercise in proper syntax.

    thanks again.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles