Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Switch doesn't work


  • Please log in to reply

#1
Axelion

Axelion

    Member

  • Member
  • PipPipPip
  • 179 posts
Hello, I'm trying to make a switch statement code because there are too many objects if I use if and else statement.
The format of the code I wrote is like this,

{
switch(randomnumber)
Case 0:
document.images.src = "mypicture.jpeg";
title= "mypicture";
break;
Case 1:
.....................
...............
}

but for some reason the switch function doesn't want to execute =(
I wonder why?! Is there a noob guide on how to make switch statement inside javascript?? And is there a major rule that I must understand on using switch statement? Is there a program that can find error inside my script?
  • 0

Advertisements


#2
Major Payne

Major Payne

    Retired Staff

  • Retired Staff
  • 5,307 posts
Are you trying to switch images at random or in some order? If so, don't try to re-invent the wheel as ther are so many good scripts already available that allow you to set them and move on to other stuff.
  • 0

#3
Axelion

Axelion

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 179 posts

Are you trying to switch images at random or in some order? If so, don't try to re-invent the wheel as ther are so many good scripts already available that allow you to set them and move on to other stuff.


Thanks a lot for the fast reply! Actually I fixed it a minute after I posted this. The extension .jpeg that I put caused the function to not working. It supposed to be .jpg =) I'm trying to switch the image randomly.
By the way, do you know how to put a caption that correspond with the image?

Edited by Axelion, 25 November 2009 - 02:37 AM.

  • 0

#4
Major Payne

Major Payne

    Retired Staff

  • Retired Staff
  • 5,307 posts
It would work with "jpeg", but only if images actually were using the "jpeg" extension and not the "jpg". Both are accepted although "jpg" is preferred.

Captions would be done for each image using the document.write(''). Not sure since I don't know how all your JS is functioning, but try it.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP