Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error someone help please

    im trrying to get this random image with link to work
    but i get this error "untermenated string constant"
    Code:
    <script language="javascript">
    <!--
    
    var b1dis = "<a href=\"";
    var bdis = "\"><img src=\"";
    var edis = " width=\"100\" height=\"100\" alt=\"some text\" border=\"0\"></a>";
    var rnumb = "";
    var img = "";
    
    rnumb += Math.floor(Math.random()*3);
    img = rnumb;
    if (img == "0") {
    document.write(b1dis+ "page1.html" +bdis+ "/1.gif"" +edis);
    }
    if (img == "1") {
    document.write(b1dis+ "page2.html" +bdis+ "/1.gif"" +edis);
    }
    if (img == "2") {
    document.write(b1dis+ "page3.html" +bdis+ "/1.gif"" +edis);
    }
    // -->
    </script>

  • #2
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Corrections made in red. The "unterminated string constant" error was due to the missing backslashes that are in red.

    Code:
    <script language="javascript">
    <!--
    
    var b1dis = "<a href=\"";
    var bdis = "\"><img src=\"";
    var edis = " width=\"100\" height=\"100\" alt=\"some text\" border=\"0\"></a>";
    var rnumb;
    
    rnumb += Math.floor(Math.random()*3);
    
    if (rnumb == 0) {
    document.write(b1dis+ "page1.html" +bdis+ "/1.gif\"" +edis);
    }
    if (rnumb == 1) {
    document.write(b1dis+ "page2.html" +bdis+ "/1.gif\"" +edis);
    }
    if (rnumb == 2) {
    document.write(b1dis+ "page3.html" +bdis+ "/1.gif\"" +edis);
    }
    // -->
    </script>
    -Shane

  • #3
    New Coder
    Join Date
    Feb 2005
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i still get the same error

    Code:
    <script language="javascript">
    <!--
    
    var b1dis = "<a href=\"";
    var bdis = "\"><img src=\"http://integy.automated-shops.com/";
    var edis = " width=\"100\" height=\"100\" border=\"0\"></a>";
    var rnumb;
    
    rnumb += Math.floor(Math.random()*3);
    
    if (rnumb == 0) {
    document.write(b1dis+ "page1.html" +bdis+ "/1.gif"" +edis);
    }
    if (rnumb == 1) {
    document.write(b1dis+ "page2.html" +bdis+ "/1.gif"" +edis);
    }
    if (rnumb == 2) {
    document.write(b1dis+ "page3.html" +bdis+ "/1.gif"" +edis);
    }
    // -->
    </script>

  • #4
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    That's because you didn't include the red backslashes that I put in there.

    document.write(b1dis+ "page1.html" +bdis+ "/1.gif\"" +edis)

    Don't forget the two others.

    -Shane


  •  

    Posting Permissions

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