...

View Full Version : need some help with this javascript code



sndesouza
03-12-2012, 06:45 PM
I'm trying to get a drop down box to change the image i've managed to get it working for one but can't seem to get it working when both scripts are on. any help would be much appreciated!


http://humza-productions.co.uk/test/

this is the code i'm using, it's for the baseball jacket one but the one that's working live on the website is currently working for the hoodie





<script type="text/javascript">
window.onload=function()
{


bp='images/', //base url of your images
imgnum=3, //Number of your images. This should match on your comboboxes options.
thumb=document.getElementById('sho1'), //id of your image that will be changing
combobox=document.getElementsByName('os1')[0]; // id of your combobox.


combobox.onchange=function()
{
thumb.src=bp+'shop'+this.value+'.png';
}
}
</script>

2reikis
03-12-2012, 08:33 PM
From what I can see of your code, you have two selects but only programmed for one. The block of code you posted needs to be duplicated for each combobox on the page. for example.


bp='images/', //base url of your images
imgnum0=3, //Number of your images. This should match on your comboboxes options.
thumb0=document.getElementById('sho0'), //id of your image that will be changing
combobox0=document.getElementsByName('os1')[0]; // id of your combobox.


combobox0.onchange=function()
{
thumb.src=bp+'shop'+this.value+'.png';
}

bp='images/', //base url of your images
imgnum1=7, //Number of your images. This should match on your comboboxes options.
thumb=document.getElementById('sho1'), //id of your image that will be changing
combobox1=document.getElementsByName('os1')[1]; // id of your combobox.


combobox1.onchange=function()
{
thumb.src=bp+'shop'+this.value+'.png';
}

sndesouza
03-13-2012, 05:49 AM
From what I can see of your code, you have two selects but only programmed for one. The block of code you posted needs to be duplicated for each combobox on the page. for example.


bp='images/', //base url of your images
imgnum0=3, //Number of your images. This should match on your comboboxes options.
thumb0=document.getElementById('sho0'), //id of your image that will be changing
combobox0=document.getElementsByName('os1')[0]; // id of your combobox.


combobox0.onchange=function()
{
thumb.src=bp+'shop'+this.value+'.png';
}

bp='images/', //base url of your images
imgnum1=7, //Number of your images. This should match on your comboboxes options.
thumb=document.getElementById('sho1'), //id of your image that will be changing
combobox1=document.getElementsByName('os1')[1]; // id of your combobox.


combobox1.onchange=function()
{
thumb.src=bp+'shop'+this.value+'.png';
}

cheers! worked perfectly, thank you!

sndesouza
03-13-2012, 05:52 AM
From what I can see of your code, you have two selects but only programmed for one. The block of code you posted needs to be duplicated for each combobox on the page. for example.


bp='images/', //base url of your images
imgnum0=3, //Number of your images. This should match on your comboboxes options.
thumb0=document.getElementById('sho0'), //id of your image that will be changing
combobox0=document.getElementsByName('os1')[0]; // id of your combobox.


combobox0.onchange=function()
{
thumb0.src=bp+'shop'+this.value+'.png';
}

bp='images/', //base url of your images
imgnum1=7, //Number of your images. This should match on your comboboxes options.
thumb1=document.getElementById('sho1'), //id of your image that will be changing
combobox1=document.getElementsByName('os1')[1]; // id of your combobox.


combobox1.onchange=function()
{
thumb1.src=bp+'shop'+this.value+'.png';
}

cheers! worked perfectly after a little tweaking. You also needed to define a number for the thumb part, I noticed you changed it for the first one but not the others which helped and was able to fix this. thank you!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum