Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old February 14th, 2005, 06:51 PM
developer_x developer_x is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 9 developer_x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
how to change image with drop down menu's options

I want to make a script which would enable me to do change image when a new option is selected from a drop down menu. Please view this link:

ebags.com/durango_leather_works/laptop_shuttle/product_detail/index.cfm?modelid=48390

I got to know that the event used for the options of drop down menu is "onChange" .i.e. It is with this event that the image is changed. But as I dont know javasript, I haven't succeeded as yet in doing what the ebags.com has done.

I am copying a code and a lil bit explaination from a book. It is used for changing images with the onMouseOver and onMouseOut events. If someone could help me to change it to achieve, my required effect, it will be really great.

*******
<html>
<head>

<script language="JavaScript">
<!-- hide

// ************************************************** ****
// Script from Stefan Koch - Voodoo's Intro to JavaScript
// http://rummelplatz.uni-mannheim.de/~skoch/js/
// JS-book: http://www.dpunkt.de/javascript
// You can use this code if you leave this message
// ************************************************** ****

// ok, we have a JavaScript browser
var browserOK = false;
var pics;

// -->
</script>

<script language="JavaScript1.1">
<!-- hide

// JavaScript 1.1 browser - oh yes!
browserOK = true;
pics = new Array();

// -->
</script>



<script language="JavaScript">
<!-- hide

var objCount = 0; // number of (changing) images on web-page

function preload(name, first, second) {

// preload images and place them in an array

if (browserOK) {
pics[objCount] = new Array(3);
pics[objCount][0] = new Image();
pics[objCount][0].src = first;
pics[objCount][1] = new Image();
pics[objCount][1].src = second;
pics[objCount][2] = name;
objCount++;
}
}

function on(name){
if (browserOK) {
for (i = 0; i < objCount; i++) {
if (document.images[pics[i][2]] != null)
if (name != pics[i][2]) {
// set back all other pictures
document.images[pics[i][2]].src = pics[i][0].src;
} else {
// show the second image because cursor moves across this image
document.images[pics[i][2]].src = pics[i][1].src;
}
}
}
}

function off(){
if (browserOK) {
for (i = 0; i < objCount; i++) {
// set back all pictures
if (document.images[pics[i][2]] != null)
document.images[pics[i][2]].src = pics[i][0].src;
}
}
}

// preload images - you have to specify which images should be preloaded
// and which Image-object on the wep-page they belong to (this is the first
// argument). Change this part if you want to use different images (of course
// you have to change the body part of the document as well)

preload("link1", "img1f.gif", "img1t.gif");
preload("link2", "img2f.gif", "img2t.gif");
preload("link3", "img3f.gif", "img3t.gif");

// -->
</script>
<head>



<body>
<a href="link1.htm" onMouseOver="on('link1')"
onMouseOut="off()">
<img name="link1" src="link1f.gif"
width="140" height="50" border="0"></a>

<a href="link2.htm" onMouseOver="on('link2')"
onMouseOut="off()">
<img name="link2" src="link2f.gif"
width="140" height="50" border="0"></a>

<a href="link3.htm" onMouseOver="on('link3')"
onMouseOut="off()">
<img name="link3" src="link3f.gif"
width="140" height="50" border="0"></a>
</body>
</html>

This script puts all images in an array pics. The preload() function which is called in the beginning builds up this array. You can see that we call the preload() function like this:

preload("link1", "img1f.gif", "img1t.gif");

This means that the script should load the two images img1f.gif and img1t.gif. The first image is the image which should be displayed when the mousecursor isn't inside the image area. When the user moves the mousecursor across the image area the second image is shown. With the first argument "img1" of the call of the preload() function we specify which Image-object on the web-page the two preloaded images belong to. If you look into the <body> part of our example you will find an image with the name img1. We use the name of the image (and not its number) in order to be able to change the order of the pictures without changing the script.
The two functions on() and off() are being called through the event-handlers onMouseOver and onMouseOut. As images cannot react to the events MouseOver and MouseOut we have to put a link around the images.
As you can see the on() function sets back all other images. This is necessary because it could happen that several images are highlighted (the event MouseOut does not occur for example when the user moves the cursor from an image directly outside the window).

***

Regards, Irfan

Reply With Quote
  #2  
Old February 18th, 2005, 03:49 PM
mgalesic mgalesic is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Croatia
Posts: 92 mgalesic User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 2 m 57 sec
Reputation Power: 3
RE: how to change image with drop down menu's options

I didn't have time to read your code but you can easily change image from drop down menu:

use onChange()
and call java script function with parameter what is value of drop down item, and thats your image name.

Your function should take the parameter and do next:

function ChangeImage(picture){
document.imagename.src = picture;
}

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > how to change image with drop down menu's options


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 12 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek