[SOLVED] Changing pictures on same page

This is a discussion on "[SOLVED] Changing pictures on same page" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Changing pictures on same page are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 2nd, 2007, 19:49
Reputable Member
Join Date: May 2007
Location: Margate
Age: 24
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Changing pictures on same page

Good evening,

how do i go about changing a picture on a page without the page having to reload.

For example, you have a shirt, same design 5 different colours, you want to display 1 on the page but have a button on the page that changes the colour. Not to select a colour just to move to the next colour.

Any help will be greatful

Cheers

Dan

  #2 (permalink)  
Old Oct 2nd, 2007, 19:53
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Changing pictures on same page

this would require JavaScript. I'm sure someone can recommend a script.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
  #3 (permalink)  
Old Oct 2nd, 2007, 20:39
welshstew's Avatar
Lead Administrator

SuperMember
Join Date: May 2007
Location: inside the outside
Posts: 1,388
Blog Entries: 13
Thanks: 1
Thanked 17 Times in 15 Posts
Re: Changing pictures on same page

ok, this should work

put this in your head section

Code: Select all
<script type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
then in your html you need the following to identify the main image (before the rollover swap)
Code: Select all
<img width="350" height="350" id="thisimagename" name="thisimagename" src="/images/image1.gif"/>
changing the id and name to whatever you want.

then for each link option (green, red, etc) you need the following
Code: Select all
<a onmouseover="MM_swapImage('thisimagename','','/images/image1red.gif',1)" href="javascript:;"><img width="15" height="15" border="0" src="/images/image1red_icon.gif"/> RED </a>
the blue indicates the image you want to swap it to.

let me know if that helps, and post a link once you have implemented it so that we can have a look.

Stew
__________________
WelshStew
Lead Administrator

tierney rides tboard - uk site | xtreme wales - extreme clothing
If you think I've helped, click the "Thanks"
webforumz - facebook | LinkedIn
Last Blog Entry: Web Standards Curriculum Launched (Jul 8th, 2008)

Last edited by karinne; Oct 2nd, 2007 at 21:19. Reason: just checking something.
  #4 (permalink)  
Old Oct 2nd, 2007, 21:12
Reputable Member
Join Date: May 2007
Location: Margate
Age: 24
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Changing pictures on same page

Cheers for the info so quick have tested it (its great), might be able to post a link tonight if i finsh it.

Cheers
Dan
  #5 (permalink)  
Old Oct 2nd, 2007, 21:21
welshstew's Avatar
Lead Administrator

SuperMember
Join Date: May 2007
Location: inside the outside
Posts: 1,388
Blog Entries: 13
Thanks: 1
Thanked 17 Times in 15 Posts
Re: Changing pictures on same page

cool, would be interested to see how you implement this.
__________________
WelshStew
Lead Administrator

tierney rides tboard - uk site | xtreme wales - extreme clothing
If you think I've helped, click the "Thanks"
webforumz - facebook | LinkedIn
Last Blog Entry: Web Standards Curriculum Launched (Jul 8th, 2008)
  #6 (permalink)  
Old Oct 2nd, 2007, 21:45
welshstew's Avatar
Lead Administrator

SuperMember
Join Date: May 2007
Location: inside the outside
Posts: 1,388
Blog Entries: 13
Thanks: 1
Thanked 17 Times in 15 Posts
Re: Changing pictures on same page

just looking to buy some new threads when I came across meatandcheese who are doing the same thing but in a slightly different way. you can just *borrow* their code if you want

Stew
__________________
WelshStew
Lead Administrator

tierney rides tboard - uk site | xtreme wales - extreme clothing
If you think I've helped, click the "Thanks"
webforumz - facebook | LinkedIn
Last Blog Entry: Web Standards Curriculum Launched (Jul 8th, 2008)
  #7 (permalink)  
Old Oct 2nd, 2007, 23:57
Reputable Member
Join Date: May 2007
Location: Margate
Age: 24
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Changing pictures on same page

Done it,

Cheers for the assitance, have a look around the website if you wish still underconstruction. Its just a personal one.


http://hondavfrnc30.friendsworld.co....ons/index.html

thanks again

Dan
  #8 (permalink)  
Old Oct 3rd, 2007, 00:14
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Changing pictures on same page

looks great
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Closed Thread

Thread Tools

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
[SOLVED] CSS changing page colour etc R8515198 Web Page Design 10 Nov 27th, 2007 00:54
Pictures in slide show on a web page Anne Introduce Yourself 5 Feb 14th, 2007 18:48
Ive A Php Page I Need Help With My Pictures Dont Appear Were They Should jingles PHP Forum 3 Sep 24th, 2006 09:43
Changing URL without refreshing page ? Perfection Studios JavaScript Forum 4 Sep 14th, 2006 12:22
Changing css with page refresh krrish Web Page Design 3 Jul 26th, 2006 08:20


All times are GMT. The time now is 04:41.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43