...

View Full Version : Double combo with image



shadowplay
11-07-2009, 07:46 PM
hi

I wonder if someone out there can help me.

I am very new to javascript and i have manged to understand a little of a double combo box with description however I would now like to be able to not only change the comment underneth but also add an image.
This image (along with the comment) changes everytime the dropdownbox changes.
I just cant seem to add the image.
Please can anyone help
I would really appreciate it and be extremely grateful.
gr
T
:rolleyes::confused:

Philip M
11-07-2009, 08:09 PM
Show your (relevant) existing code.

shadowplay
11-07-2009, 08:26 PM
apologies.... quite right.... would have been helpful to post the code
please see below...

<form name="doublecombo">
<select name="event" size="1" onChange="redirect(this.options.selectedIndex); displaydesc()">
<option>------ please select ------</option>
<option>websites</option>
<option>searchengines</option>
</select>
<select name="stage2" size="1" onchange="displaydesc()">
<option value="">------ please select ------</option>
</select>
<input type="button" name="test" value="Go!"
onClick="go()">
<br />
<span id="descriptions" align="left" style="font:13px Arial"></span>
</form>
<script>

var groups=document.doublecombo.event.options.length
var group=new Array(groups)
var descr=new Array(groups)
for (i=0; i<groups; i++){
group[i]=new Array()
descr[i]=new Array()
}

group[0][0]=new Option("","")
descr[0][0]= "";

group[1][0]=new Option("yahoo","http://www.yahoo.co.uk")
descr[1][0]= "yahoo is best";
group[1][1]=new Option("News.com","http://www.news.com")
descr[1][1]= "news com gives up to date news";
group[1][2]=new Option("Wired News","http://www.wired.com")
descr[1][1]= "wired news is wired";

group[2][0]=new Option("Hotbot","http://www.hotbot.com")
descr[2][0]= "hot has a hot bot";
group[2][1]=new Option("Infoseek","http://www.infoseek.com")
descr[2][1]= "do you seek info?";
group[2][2]=new Option("Excite","http://www.excite.com")
descr[2][2]= "ahem...";
var temp=document.doublecombo.stage2

function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}

function go(){
location=temp.options[temp.selectedIndex].value
}

function displaydesc(){
var desc=descr[document.doublecombo.event.selectedIndex][document.doublecombo.stage2.selectedIndex];
if (document.all) descriptions.innerHTML=desc;
else if (document.getElementById) document.getElementById("descriptions").innerHTML=desc
}

displaydesc()
//-->
</script>

godofreality
11-08-2009, 07:48 AM
you should wrap your code in [ CODE ] code goes here [/ CODE ] tags when posting code and as for a possible fix you could add this


<img id="pic" src="" alt="" />

after


<span id="descriptions" align="left" style="font:13px Arial"></span>


and add in sum img handling code to your javascript like so


var img = new Array(groups);
img[1][0] = "yahoo.jpg"; // etc etc u get the idea here i hope


and this part here


function displaydesc(){
var desc=descr[document.doublecombo.event.selectedIndex][document.doublecombo.stage2.selectedIndex];
imgX=img[document.doublecombo.event.selectedIndex][document.doublecombo.stage2.selectedIndex];
if (document.all) {descriptions.innerHTML=desc; }
else if (document.getElementById) { document.getElementById("descriptions").innerHTML=desc; }
document.getElementById("pic").src = imgX;
document.getElementById("pic").alt = desc; }
}


also as a side note u can prolly get rid of the document.all stuff



function displaydesc(){
var desc=descr[document.doublecombo.event.selectedIndex][document.doublecombo.stage2.selectedIndex];
imgX=img[document.doublecombo.event.selectedIndex][document.doublecombo.stage2.selectedIndex];
document.getElementById("descriptions").innerHTML=desc;
document.getElementById("pic").src = imgX;
document.getElementById("pic").alt = desc;
}

that right there should be all u need in that function for it to work in all browsers currently

shadowplay
11-08-2009, 10:12 AM
thanks godofreality you are the best!!!
:thumbsup::thumbsup::thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum