Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > JavaScript and CSS

JavaScript and CSS Extensible Markup Language, Java Script, and CSS questions here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-18-2007, 08:41 AM
wilk3sy wilk3sy is offline
Newbie
 
Join Date: Dec 2007
Posts: 25
Rep Power: 3
wilk3sy is on a distinguished road
Default Change image help

hey guys, ive decided to have a dabble at javascript, on what i thought would be a minimalistic scale, and something not too complex... obviously i was wrong.

basically what i have is an image on an html page, and a set of links underneath labelled 1-6. What i would like to do is hav the user click on one of the other numbers, and the image switch to the picture corresponding to that number.

so far i have this... but it doesnt seem to do anything as ive hit a brick wall!

JavaScript Code:
  1. <script type="text/javascript">
  2. <!--
  3.  
  4. var mainimage;
  5. var imagechange = "0";
  6.  
  7.  
  8. if(imagechange == "2"){
  9.     mainimage == "images/image2.png";
  10. }else if(imagechange == "3"){
  11.     mainimage == "images/image3.png";
  12. }else if(imagechange == "4"){
  13.     mainimage == "image4";
  14. }else if(imagechange == "5"){
  15.     mainimage == "image5";
  16. }else if(imagechange == "6"){
  17.     mainimage == "image6";
  18. } else {
  19.     mainimage == "image1";}
  20.  
  21. //-->
  22. </script>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 12-18-2007, 03:17 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 26
Posts: 5,963
Last Blog:
SAP, ERP and EDI
Rep Power: 20
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

Nothing strikes me as being wrong here. Can you post your link HTML code?
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
Don't hesitate to ask any questions that you have! Check out our ASCII Calculator!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-18-2007, 06:57 PM
wilk3sy wilk3sy is offline
Newbie
 
Join Date: Dec 2007
Posts: 25
Rep Power: 3
wilk3sy is on a distinguished road
Default

well... if the javascript is right, then i guess that just means its implementing the javascript into the html tha tis the problem....

what i want is basically

<img src="mainimage"></img>

main image being taken from the javascript code, which should signify 1 of the 6 images.

to choose the image, i have basically written,

<a href="#" onclick="imagechange=1"></a>

something to that effect....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-19-2007, 05:45 AM
fahlyn's Avatar   
fahlyn fahlyn is offline
Learning Programmer
 
Join Date: Nov 2007
Age: 25
Posts: 35
Rep Power: 4
fahlyn is on a distinguished road
Send a message via ICQ to fahlyn Send a message via AIM to fahlyn Send a message via MSN to fahlyn Send a message via Yahoo to fahlyn
Default

I would suggest starting out with an empty <div> and use your javascript to build the <img src="whatever" /> as the innerHTML as the empty div...when when your links are clicked just change the innerHTML of your div to a different <img src="somethingelse" />.

Unless...you have a default image that you always want to display when the page loads...then i would suggest something like

<img src="default.jpg" id="image"/>

then when your links are clicked change document.getElementById('image').src = "newimage.jpg";

(or $('image').src = "newimage.jpg"; if you use prototype.

Good Luck
__________________
Visit My Google Group Here: Web Development Innovation
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make image straight - Photoshop ahsan16 Photoshop Tutorials 56 07-30-2008 03:11 PM
JavaScript:Tutorial, MouseOver Image Change TcM Javascript 2 10-30-2007 01:51 PM
image button problem ikkeugh Visual Basic Programming 14 10-03-2007 03:55 PM
Resize Images And Maintain Original Sharpness AfTriX Photoshop Tutorials 7 04-20-2007 09:55 AM
Using change management Cosmet General Programming 2 10-30-2006 06:16 PM


All times are GMT -5. The time now is 11:29 PM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
LogicKills ........ 20.00000
sam ........ 20.00000
gaylo565 ........ 18.00000
|pH| ........ 15.00000
WingedPanther ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads