CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: JS linking help

  1. #1
    Join Date
    Jan 2011
    Location
    Orange County, CA
    Posts
    82

    Angry JS linking help

    OK, i have 2 questions that are basically about the same concept, linking. I know this is a very basic principle, but i really never learned how (as far as i know, these links work fine), so please bare with me.
    I have two scripts (one JS and one CSS) that work fine when written in my HTML document, but when i try to link them, they dont work, can anyone tell me what im doing wrong please?

    Non-Linking Page (with relevant script--does work):
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    	
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <!-- Some of the header i have also left blank just for this example -->
    	
        <title> </title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <meta name="kwrd" content=" " />
        <meta name="desc" content=" " />
        <script language="javascript" type="text/javascript">
        <!-- Hide from old browsers
    
          adImages = new Array("/images/banner1.jpg","/images/banner2.jpg","/images/banner3.jpg")
          thisAd = 0
          imgCt = adImages.length
          function rotate() {
          if (document.images) {
          thisAd++
          if (thisAd == imgCt) {
          thisAd = 0
          }
          document.adBanner.src=adImages[thisAd]
          setTimeout("rotate()", 3 * 1000)
          }
          }
          // End hide script from old browsers -->
          </script>
          <style type="text/css">
            div#background {background: #808080;}	
          </style>
      </head>
      
      <!-- I have scipped over most of this part of the document, but this is the relevant script -->
      
            <td valign="top"  width="200">
              <table align="left" border="1" width="200">
                <tr>
                  <td align="center">
                    <body onload="rotate()">
                      <img src="/images/banner2.gif" height="150" width="200" name="adBanner" alt="Banner" />
    	        </body>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
    	  
      <!-- End of Relevant Script -->
    Linking Page (with relevant script--does NOT work)
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    	
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <!-- Some of the header i have also left blank just for this example -->
    	
        <title> </title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <meta name="kwrd" content=" " />
        <meta name="desc" content=" " />
        <script src="/script/script1.js" language="javascript" type="text/javascript"></script>
        <style src="/styles/style1.css" type="text/css"></style>
      </head>
      
      <!-- I have scipped over most of this part of the document, but this is the relevant script -->
      
            <td valign="top"  width="200">
              <table align="left" border="1" width="200">
                <tr>
                  <td align="center">
                    <body onload="rotate()">
                      <img src="/images/banner2.gif" height="150" width="200" name="adBanner" alt="Banner" />
    	        </body>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
    	  
      <!-- End of Relevant Script -->
    Link 1 (Javascript)
    Code:
    <!-- Hide from old browsers
    
    adImages = new Array("/images/LaPuertaAbierta.jpg","/images/Getsemani1.jpg","/images/CentroCristianoShekina.jpg")
    thisAd = 0
    imgCt = adImages.length
    function rotate() {
    if (document.images) {
    thisAd++
    if (thisAd == imgCt) {
    thisAd = 0
    }
    document.adBanner.src=adImages[thisAd]
    setTimeout("rotate()", 3 * 1000)
    }
    }
    
    // End hide script from old browsers -->
    Link 2 (CSS)
    Code:
    div#background {background: #808080;}
    Thank you for your time.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: JS linking help

    Lots of problems here. You really need to stop what you're doing and read some HTML tutorials! Here is one I highly recommend.

    #1 The body tag is not an inner element! It is only encased within <html>...nothing else!

    #2 The <style> tag doesn't even have an src attribute as you have tried to force upon it. That's why your document is not going to be styled.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jan 2011
    Location
    Orange County, CA
    Posts
    82

    Re: JS linking help

    Quote Originally Posted by PeejAvery View Post
    Lots of problems here. You really need to stop what you're doing and read some HTML tutorials! Here is one I highly recommend.

    #1 The body tag is not an inner element! It is only encased within <html>...nothing else!

    #2 The <style> tag doesn't even have an src attribute as you have tried to force upon it. That's why your document is not going to be styled.
    hay, thanks for the link. im self-taught so im not the best
    as for the code; i replaced the <style> with a <link> and it works fine, as for the JS link....well....i just forgot to upload it on my server O.o
    thanks anyways, i also fixed the <body>, i didnt even know about that one!

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured