Need Javascript Help

Discussion in 'Gaming' started by r3m1x, Feb 28, 2008.

  1. r3m1x

    r3m1x Well-Known Member

    Posts:
    2,260
    Likes Received:
    0
    Joined:
    Jun 21, 2005
    Location:
    New York City
    Right, so I have this code. And I can't figure out why is won't work. It's really basic stuff, but I can't find whats wrong with it.
    Code:
    <html>
      <head>
        <title>Testing scripts</title>
        <script type="text/javascript">
            
            var views = 0;
            
            function swapPic(objectName, newFile)
            {
                objectName.src=newFile;
            }
            
            function getNextPicture()
            {
                switch(views)
                {
                    case 0: {swapPic(image, adversity.jpg); views++;} break;
                    case 1: {swapPic(image, agony.jpg); views++;} break;
                    case 2: {swapPic(image, ambition.jpg); views++;} break;
                    case 3: {swapPic(image, apathy.jpg); views=0;} break;
                    default: {views=0;} break;
                }    
            }    
        </script>
      </head>
      <body>
          [img]achievement.jpg[/img]
      </body>
    </html>
    achievement, adversity, agony, ambition, and apathy.jpg are all located in the same directory as this file. The idea is for the pictures to loop through everytime you mouse over it, but something is wrong and views doesn't want to go above 0.
     
  2. xlink

    xlink GR's Tech Enthusiast

    Posts:
    8,054
    Likes Received:
    3
    Joined:
    Nov 19, 2004
    now I'm tired and i suck at javascript...

    but do you have anything starting the function?
     
  3. MattMann

    MattMann Well-Known Member

    Posts:
    334
    Likes Received:
    0
    Joined:
    May 31, 2004
    Location:
    Chicago, IL USA
    You mispelt onmouseover

    then your gonna into more problems because your files should be in quotes in the case statement.
     
  4. r3m1x

    r3m1x Well-Known Member

    Posts:
    2,260
    Likes Received:
    0
    Joined:
    Jun 21, 2005
    Location:
    New York City
    I can't believe I didn't see that. That and the function required quotes around filenames. Got it working so thanks for the help.
     

Share This Page