473,388 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

the ability to change an image through an pointer of dropdown

Is this possible to ...

I wish to get the value of a dropdown select but gets is indexable value
(dont know if that is the right term) if that is possible (the position it
assigned get assigned by the position on the list)

this is so i can then pass it to the array called pictureimage to get the
correct filename (similar to the picturetext part of this routine) and then
the final line on the fuction is to change an original image with a name of
base to show the case which is selected..

I had the routine originally using the value which was standardcase, case1,
case2, case3 then looking up the value to pass the image information...

i dont know if this is possible...

so if some can advise i be very gratefull
thanks

Nick
// function to change picture and text of case selection

function changepicture()

if (ns4)
{document.myform.dropdownchanger.value=picturetext[document.myform.itemname4.options.selectedIndex]
}

if (ie4) {document.all['dropdownchanger'].innerHTML ='<p>' +
picturetext[document.myform.itemname4.options.selectedIndex] + '</p>' }
else if (dom) {document.getElementById("dropdownchanger").innerH TML ='<p>'
+ picturetext document.myform.itemname4.options.selectedIndex] + '</p>' }

document.base.src=eval((document.myform.itemname4. options[document.myform.itemname4.options.selectedIndex].value))//set up images and link to the filenames pictureimage= new Array()pictureimage[0] = "images/casepackage.jpg"//default pictureimage[1] ="images/a24.jpg" //first pictureimage[2] = "images/a23.jpg" //secondpictureimage[3] = "images/a22.jpg" //third pictureimage[4] ="images/a40a.gif" //forth pictureimage[5] = "images/a42.jpg" //fifthpictureimage[6] = "images/a42.jpg" //sixth pictureimage[7] ="images/a33.jpg" //seventh pictureimage[8] = "images/a41.jpg"//eighth// Insert your text for each picture picturetext= new Array();picturetext[0]="Standard Case Included In Package"; picturetext[1]="Case 1 :8024-C4 All Black Neon Midi Case 400W + £26.50."; picturetext[2]="Case 2 :8024-C34 Black/Silver Neon Midi Case 400W +£26.50."; picturetext[3]="Case 3: 8024-B43 Silver/Black Neon Midi Case 400W +£26.50."; picturetext[4]="Case4 : 8023-B3 All Silver Neon Midi Case 400W +£26.50."; picturetext[5]="Case5 : 8001-C34 Black/Silver Neon Midi Case 400W +£26.50.";picturetext[6]="Case 6 : 8005-B32 Silver/Blue Neon Midi Neon Case 350W+£26.50."; picturetext[7]="Case 7 : 6063-CA Black/Silver Midi Case 400W +£26.50."; picturetext[8]="Case 8 : 8004-C4 All Black Neon Midi Case 400W +£26.50.";<select id="total2" name=itemname4 onchange="changepicture()"size="1"> <option value="standardcase {0.00}" selected>StandardCase</option> <option value="case1 {26.50}">All Black Neon MidiCase</option> <option value="case2 {26.50}">Black/Silver Neon MidiCase400W</option> <option value="case3 {26.50}">Silver/Black Neon MidiCase400W</option> <option value="case4 {26.50}">All Silver Neon MidiCase 400W</option> <option value="case5 {26.50}">Black/Silver Neon MidiCase400W</option> <option value="case6 {26.50}">Silver/Blue Neon MidiNeon Case350W</option> <option value="case7 {26.50}">Black/Silver MidiCase 400W </option> <option value="case8 {26.50}">All Black Neon MidiCase 400W</option></select>

Jul 23 '05 #1
2 1829
Nick Calladine wrote:
Is this possible to ...

I wish to get the value of a dropdown select but gets is indexable
value (dont know if that is the right term) if that is possible
(the position it assigned get assigned by the position on the list)
You are after the selectedIndex property of the select:

var theSelectedIndexValue = document.formA.selectA.selectedIndex;

But this seems a strange request - you are making a dependency on the
option and array elements having the same index value. You have
available the option value and the text, either of which could be
used as a key to the elements in the image array. Using say the
value means the options and array elements don't have to be in
exactly the same sequence. You can add the key to the existing
value, the strip it out in the function.

this is so i can then pass it to the array called pictureimage to
get the correct filename (similar to the picturetext part of this
routine) and then the final line on the fuction is to change an
original image with a name of base to show the case which is
selected..

I had the routine originally using the value which was
standardcase, case1, case2, case3 then looking up the value to pass
the image information...

i dont know if this is possible...

so if some can advise i be very gratefull thanks

Nick
// function to change picture and text of case selection

function changepicture()

if (ns4)
{document.myform.dropdownchanger.value=picturetext[document.myform.itemname4.options.selectedIndex]
}

if (ie4) {document.all['dropdownchanger'].innerHTML ='<p>' +
picturetext[document.myform.itemname4.options.selectedIndex] +
'</p>' } else if (dom)
{document.getElementById("dropdownchanger").innerH TML ='<p>' +
picturetext document.myform.itemname4.options.selectedIndex] +
'</p>' }
Browser sniffing is sad. At a guess, you are adding a caption for
an image. By far the vast majority of web browsers now support
getElementById, yet it is last in your suite of tests. Here is a
copy of something posted earlier.

Browse of the group FAQ, particularly:

<URL:http://www.jibbering.com/faq/#FAQ4_15>

Check out the DynWrite stuff a very simple version is place the
following at the start of a script element outside any function:

if( !document.getElementById ){
if ( document.all ){
document.getElementById = function(id){return document.all[id];};
} else if ( document.layers ) {
document.getElementById = function(id){return document.layers[id];};
} else {
return null;
}
}

If you use the above, then the onclick script is changed to:

<select ... onclick="changepicture(this);" ...>
caption changing part of the script
becomes:

function changepicture(s) {
var x = document.getElementById('dropdownchanger');
x.innerHTML = picturetext[s.selectedIndex];
}

document.base.src=eval((document.myform.itemname4. options[

document.myform.itemname4.options.selectedIndex].value))

eval is evil and almost certainly not required, ever.

[...]

Here is a slight re-write of the clipped stuff. Note that the image
can be changed using as similar algorithm and just change the image
src attribute.

<script type="text/javascript">
function changepicture(s) {
var x = document.getElementById('dropdownchanger');
x.innerHTML = picturetext[s.selectedIndex];

// Change image (untested)
var i = document.getElementById('imageID');
i.src = pictureimage[s.selectedIndex];
}

var theOpt = document.myform.itemname4;
document.base.src = theOpt[theOpt.selectedIndex].value;

//set up images and link to the filenames
pictureimage = new Array();
pictureimage[0] = "images/casepackage.jpg"; //default
pictureimage[1] = "images/a24.jpg"; //first
pictureimage[2] = "images/a23.jpg"; //second
pictureimage[3] = "images/a22.jpg"; //third
pictureimage[4] = "images/a40a.gif"; //forth
pictureimage[5] = "images/a42.jpg"; //fifth
pictureimage[6] = "images/a42.jpg"; //sixth
pictureimage[7] = "images/a33.jpg"; //seventh
pictureimage[8] = "images/a41.jpg"; //eighth

// Insert your text for each picture
picturetext= new Array();
picturetext[0] = "Standard Case Included In Package";
picturetext[1] = "Case 1 :8024-C4 All Black Neon Midi"
+ " Case 400W + £26.50.";
picturetext[2] = "Case 2 :8024-C34 Black/Silver Neon Midi"
+ " Case 400W +£26.50.";
picturetext[3] = "Case 3: 8024-B43 Silver/Black Neon Midi"
+ " Case 400W +£26.50.";
picturetext[4] = "Case4 : 8023-B3 All Silver Neon Midi"
+ " Case 400W +£26.50.";
picturetext[5] = "Case5 : 8001-C34 Black/Silver Neon Midi"
+ " Case 400W +£26.50.";
picturetext[6] = "Case 6 : 8005-B32 Silver/Blue Neon Midi"
+ " Neon Case 350W+£26.50.";
picturetext[7] = "Case 7 : 6063-CA Black/Silver Midi"
+ " Case 400W +£26.50.";
picturetext[8] = "Case 8 : 8004-C4 All Black Neon Midi"
+ " Case 400W +£26.50.";

</script>
<select id="total2" name=itemname4
onchange="changepicture(this)" size="1">
<option value="standardcase {0.00}" selected>StandardCase</option>
<option value="case1 {26.50}
">All Black Neon MidiCase</option>
<option value="case2 {26.50
}">Black/Silver Neon MidiCase400W</option>
<option value="case3 {26.50
}">Silver/Black Neon MidiCase400W</option>
<option value="case4 {26.50
}">All Silver Neon MidiCase 400W</option>
<option value="case5 {26.50
}">Black/Silver Neon MidiCase400W</option>
<option value="case6 {26.50
}">Silver/Blue Neon MidiNeon Case350W</option>
<option value="case7 {26.50
}">Black/Silver MidiCase 400W </option>
<option value="case8 {26.50
}">All Black Neon MidiCase 400W</option>
</select>

<p id="dropdownchanger"></p>
--
Rob
Jul 23 '05 #2
RobG wrote:
[...]
if( !document.getElementById ){
if ( document.all ){
document.getElementById = function(id){return document.all[id];};
} else if ( document.layers ) {
document.getElementById = function(id){return document.layers[id];};
} else {
return null;
}
}


Ah, just discovered Richard C's response to an earlier post, the
above should be:

if( !document.getElementById ){
if ( document.all ){
document.getElementById = function(id){
return document.all[id];
};
} else if ( document.layers ) {
document.getElementById = function(id){
return document.layers[id];
};
} else {
document.getElementById = function(){return null;};
}
}

The last 'else' is important where none of getElementById,
document.all or document.layers is supported.
[...]

--
Rob
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jay | last post by:
I have a script being called by clicking image. In order to present image as clickable I like to have mouse pointer changes to a hand when the pointer is over the image. So I put <area...
3
by: Kristof Thys | last post by:
Hello, I'm writing a ASP.net webservice wich will visualize an image, generated by another application. The generated image is a char*. I can transform this to a String*, but I want to view it...
1
by: Yuriy | last post by:
I need to add images to dropdown control. I try to find something, but could not find anything exept ifragistic control. Any help appreciate
47
by: Albert | last post by:
So structures are useful to group variables, so you can to refer to a collection as a single entity. Wouldn't it be useful to also have the ability to collect variable and functions? Ask K&R...
2
by: Billy | last post by:
Change DataGrid EditControl On Data Value Hi, I have a datagrid, and on editing, I want to change the control in the third colunm based on the value of the first column. The value in the...
6
by: Bruce | last post by:
Although I have quite a bit of WinForms experience, I am new to ASP.NET. So don't be surprised by the elementary question. :) I am creating a webpage with a dropdown list that allows the...
11
by: harold.gimenez | last post by:
Hi group, I am trying to change the selection of an ASP Dropdownlist just like "Orange" is selected here: http://www.w3schools.com/js/tryit.asp?filename=try_dom_option_selected The...
7
by: Dave | last post by:
Hello All, These one may be a bit tricky, and what I'd like to do may not even be possible. I would love to hear any ideas you guys have for solving this. Here is the situation: I have a form...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.