Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    Please can somebody check my code and tell me what is wrong with it?
    Code:
    totalsites = 0;
    totalgraphics = 4;
    totalother = 0;
    startsel = 1;
    
    var sites = new Array(totalsites)
    
    
    var graphics = new Array(totalgraphics)
    graphics[1] = "comingsoon01.gif";
    graphics[2] = "logo01.gif";
    graphics[3] = "logo02.gif";
    
    var other = new Array(totalother)
    
    
    function selecttype(newtype) {
    if (newtype == sitessel){document.examplepic.src = sites[startsel];}
    if (newtype == graphicsel) {document.examplepic.src = graphics[startsel];}
    if (newtype == othersel) {document.examplepic.src = other[startsel];}
    Please do not re-write the code, just tell me what i am doing wrong :cheeky:

    Thanks :squareeyed:
    JR

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    For one thing, get in the habit of loving newlines...that lat bit is impossible to read (although coincidently because it's only one statement in the if you don't need the braces.

    Also, not sure if this is the problem, but array indicies start at 0, not 1.

    ...and finally, in your if blocks, those arrays don't exist (sites and other).
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    thanks for the help, but no luck

    i did everything you said and cut it down to this....
    Code:
    totalsites = 0;
    totalgraphics = 4;
    totalother = 0;
    startsel = 1;
    
    var graphics = new Array(totalgraphics)
    graphics[0] = "comingsoon01.gif";
    graphics[1] = "logo01.gif";
    graphics[2] = "logo02.gif";
    
    function selecttype(newtype) {
    if (newtype == graphicsel) document.examplepic.src = graphics[startsel];
    }
    but it didnt work i still get the error graphicsel is undefined

    thanks :dead:
    JR

  5. #4
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Graphics might be a reserved word but I doubt it.

    It would help if you said what the error was...
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  6. #5
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    here is what is wrong...

    the page

    the js code
    JR

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    The problem is here:
    Code:
            <a href="javascript:selecttype(sitesel)">Web Sites</a><br>
            <a href="javascript:selecttype(graphicsel)">Graphic Work</a><br>
            <a href="javascript:selecttype(othersel)">Other Work</a>
    put tics around your types, like this:
    Code:
            <a href="javascript:selecttype('sitesel')">Web Sites</a><br>
            <a href="javascript:selecttype('graphicsel')">Graphic Work</a><br>
            <a href="javascript:selecttype('othersel')">Other Work</a>
    Also, do the same in your script:
    Code:
    function selecttype(newtype) {
    if (newtype == 'graphicsel') document.examplepic.src = graphics[startsel];
    }

  8. #7
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Try doing something like this:
    Code:
    <script>
    graphics = ['OOPS.jpg', 'pic1.jpg', 'pic2.jpg', 'pic3.jpg'];
    function showPic(id) {
        try {
            document.getElementById('samplePic').src = graphics[id];
        } catch (e) {
            document.getElementById('samplePic').src = graphics[0];
        }
    }
    </script>
    Then, in your html, do:
    Code:
        <a href="javascript:showPic(1)">Pic 1</a><br>
        <a href="javascript:showPic(2)">Pic 2</a><br>
        <a href="javascript:showPic(3)">Pic 3</a>

  9. #8
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    thanks transio, will try that tommorow, it is early in the morning :tired:
    JR

  10. #9
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    If it's "early in the morning", when you say "will try that tomorrow" do you mean that you're gonna try it out on Thursday? :-P

  11. #10
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    lol dont mess with my mind - i am very tired :tired:
    JR


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:47 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com