Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-17-2013, 04:19 AM   PM User | #1
samhor
New Coder

 
Join Date: Mar 2012
Location: USA
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
samhor is an unknown quantity at this point
Question javascript slideshow - can't get the first slide and last slide button to work.

Hello All,

I have made the below js slideshow but i can't seem to get the button to take you back to the first/last slide
Any ideas?
Code:
<p><center><h1> Slide Show - Devices</h1></center></p>
	    <script language="JavaScript">
var count = 0
var images = new Array('bblogo.jpg','applelogo.jpg','alogo.jpg','iphone45.jpg')
function imageslideshow( btnselection){

 if ( btnselection == 'next' && count <=2){
 count++
 }

 if ( btnselection == 'back' && count >=1){
 count --;
 }
  if ( btnselection == 'firstslide' && count >=count+1){
 count 
 if ( btnselection == 'lastslide' && count >=count+4){
 count 
 }
 
  document.getElementById("imagecount").innerHTML = (count+1)+" of 4 <br> <img src='images/"+images[count]+"'>"
  
}  
</script>
<div id="imagecount"><script>imageslideshow()</script></div>
<input type="button" value="Previous" onclick="imageslideshow('back')">
<input type="button" value="Next" onclick="imageslideshow('next')">
<input type="button" value="First Slide" onclick="imageslideshow('firstslide')">
<input type="button" value="Last Slide" onclick="imageslideshow('lastslide')">
samhor is offline   Reply With Quote
Old 01-17-2013, 07:12 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,260
Thanks: 10
Thanked 532 Times in 526 Posts
devnull69 will become famous soon enough
Oh my ... there are several issues in your code

1 - language="Javascript" should be replaced by type="text/javascript"
2 - You should get used to correct indentation of code and related brackets
Code:
var count = 0
var images = new Array('bblogo.jpg','applelogo.jpg','alogo.jpg','iphone45.jpg')

function imageslideshow( btnselection){

 if ( btnselection == 'next' && count <=2){
   count++
 }

 if ( btnselection == 'back' && count >=1){
   count --;
 }
 
 if ( btnselection == 'firstslide' && count >=count+1){
   count 
 
 if ( btnselection == 'lastslide' && count >=count+4){
   count 
 }
 
 document.getElementById("imagecount").innerHTML = (count+1)+" of 4 <br> <img src='images/"+images[count]+"'>"
  
}
Then you can immediately see that you are missing a closing } for one of the if statements

3 - In two of the if statements you just have "count" ... what do you want to do for those if's? You want to SET a certain value for count, no matter what the current value is
Code:
 if ( btnselection == 'firstslide'){
   count=0;
 }
 if ( btnselection == 'lastslide'){
   count=3;
 }
devnull69 is offline   Reply With Quote
Old 01-17-2013, 11:56 AM   PM User | #3
samhor
New Coder

 
Join Date: Mar 2012
Location: USA
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
samhor is an unknown quantity at this point
Question Update

Quote:
Originally Posted by devnull69 View Post
Oh my ... there are several issues in your code

1 - language="Javascript" should be replaced by type="text/javascript"
2 - You should get used to correct indentation of code and related brackets
Code:
var count = 0
var images = new Array('bblogo.jpg','applelogo.jpg','alogo.jpg','iphone45.jpg')

function imageslideshow( btnselection){

 if ( btnselection == 'next' && count <=2){
   count++
 }

 if ( btnselection == 'back' && count >=1){
   count --;
 }
 
 if ( btnselection == 'firstslide' && count >=count+1){
   count 
 
 if ( btnselection == 'lastslide' && count >=count+4){
   count 
 }
 
 document.getElementById("imagecount").innerHTML = (count+1)+" of 4 <br> <img src='images/"+images[count]+"'>"
  
}
Then you can immediately see that you are missing a closing } for one of the if statements

3 - In two of the if statements you just have "count" ... what do you want to do for those if's? You want to SET a certain value for count, no matter what the current value is
Code:
 if ( btnselection == 'firstslide'){
   count=0;
 }
 if ( btnselection == 'lastslide'){
   count=3;
 }
Hi

In regards to 3 -
Code:
 if ( btnselection == 'firstslide' && count >=count+1){
   count 
 
 if ( btnselection == 'lastslide' && count >=count+4){
   count 
 }
I wanted the above to take me to first and last slide as marked in bold. I thought by putting in count shown in red would take the count and take me to the first and last slide respectedly. How would i do it?
samhor is offline   Reply With Quote
Old 01-18-2013, 08:46 AM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,260
Thanks: 10
Thanked 532 Times in 526 Posts
devnull69 will become famous soon enough
You'd do it exactly as I mentioned before
Code:
 if ( btnselection == 'firstslide'){
   count=0;
 }
 if ( btnselection == 'lastslide'){
   count=3;
 }
The condition to take you to the first/last slide is ONLY the clicked button and not the current value of "count". In order to take you to the first slide, set the count to 0. In order to take you to the last slide, set the count to 3
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:38 AM.


Advertisement
Log in to turn off these ads.